I'm trying to figure out how I would go about parsing a group of files
containing raw log data (results of crontab -l) and convert this data
into a human readable format. The entries in the files are like so:
I want to get them into this format so I can enter the data into a
spreadsheet:
Cronjob | # of Servers | Every minute | Every hour | Every day | Every
week | Every month
···
-----------------------------------------------------------------------------------------
CronHere> 10 | N | N | Y | Y | Y
CronHere> 8 | Y | N | N | Y | Y
And so on. Anything that has a * would get a N in the cron job, while
anything that has anything but a * for the time would get a Y in the
results.
Can anyone give me some examples of how I might go about doing this with
ruby? Either doing it with pure ruby, or invoking awk within ruby is
fine.
Note that I left the '?' for the number of servers as that is your
problem - Think of it as an exercise for the reader
Also you might also need to match the Paul Vixie extensions for cron
such as @hourly and @daily
Thanks for the reply. This looks like a step in the right direction. The
only problem that I can think of is that the cron jobs aren't always
going to have the same time, so I don't think having the " a =
"10,25,40,55 * * * *" portion would work, as it would probably only find
one entry of that since the times the crons execute are always going to
vary.
Note that I left the '?' for the number of servers as that is your
problem - Think of it as an exercise for the reader
Also you might also need to match the Paul Vixie extensions for cron
such as @hourly and @daily
Thanks for the reply. This looks like a step in the right direction. The
only problem that I can think of is that the cron jobs aren't always
going to have the same time, so I don't think having the " a =
"10,25,40,55 * * * *" portion would work, as it would probably only find
one entry of that since the times the crons execute are always going to
vary.
split takes a second argument that specifies a limit. It will greatly
simplify parsing the lines in this case.
The a = "..." part was to allow me to give you a runnable example, you
will have to figure out how to read the crontabs yourself. I dont know
how your system is set up. Also Ammar Ali's suggestion is a
considerable improvement on my code, you should go with that.