2

What I would like to achieve is to receive an email with the failures of my VPS. I tried to do that by downloading an rss feed XML file from my VPS provider which contains all the failures, down states etc. of their servers.

Once I downloaded it, I would like to parse it in order to see if my Virtual Host number is included in any of the entries of the XML file. If yes, I should receive an email containing the entire entry that contains my Virtual Host number (well, this is not a problem at all using sendmail). I have been unsuccessfully trying to use a simple and dirty wget and grep.

This is the file I would like to parse: http://www.hetzner-status.de/en.atom

4
  • 1
    If you want to parse XML use an XML parser instead of grep. Libraries are available for every common language. Here's something to get you started: How do I parse XML in python?
    – Marco
    Jan 24, 2014 at 10:56
  • 1
    Are you really asking us to help you parse a file we can't see? Anyway, don't try to use regular expressions to parse XML files, it might wake up Tony.
    – terdon
    Jan 24, 2014 at 17:33
  • Thankyou for these start points. hetzner-status.de/en.atom this is the file I would like to parse.
    – giovi321
    Jan 24, 2014 at 18:03
  • @Marco: thank you for the suggestion, I'm very ignorant abouth python so I'd rather not using it, I would prefer a bash script. I hope I'm not being too choosy.
    – giovi321
    Jan 24, 2014 at 18:05

1 Answer 1

3

The utility you're looking for is xml2.

The xml2 command will convert an XML document into flat text. Using the URL you you gave as an example, here's a snippet of the conversion.

$ curl -sL http://www.hetzner-status.de/en.atom | xml2 | head
/feed/@xmlns=http://www.w3.org/2005/Atom
/feed/title=Hetzner Online AG - Status-Webseite
/feed/id=http://www.hetzner-status.de/
/feed/link/@href=http://www.hetzner-status.de/en.atom
/feed/link/@rel=self
/feed/link/@type=application/atom+xml
/feed/link
/feed/link/@href=http://www.hetzner-status.de/
/feed/updated=2014-01-24T18:00:04Z
/feed/author/name=Hetzner Online AG

Each line is a key, which is an XML path, separated from its value by =. You should be able to get the rest using grep/cut or awk.

1
  • Thank you very much bahamat! I will check this out within tomorrow and I'll let you know how it went, but it looks exactly what I was looking for.
    – giovi321
    Jan 24, 2014 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .