BradHodges wrote:I am not following the part about multiple servers.
You might want to explain that a bit more. Are you parsing crontab output from multiple servers?
How are those multiple crontab outputs presented to you?
/whatever/crontabs/server1.txt
/whatever/crontabs/server2.txt
/whatever/crontabs/server3.txt
/whatever/crontabs/server4.txt
/whatever/crontabs/server5.txt
????
Yeah, that's the idea. Say I have 10 servers with the raw crontab output in each file - all in files named server.log, server2.log, etc. I'm parsing all of them to come up with the output I mentioned in my original post.
If actually counting the number of times a cron job shows up and outputting a total sum is too difficult, I could at least get the raw output from each file and do the addition myself to get the total amount a cron job shows up.
So, say I have 10 servers with:
/some/cron/here/
And 8 servers with:
/another/cron/here/
The final format I'm aiming for would be like so:
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
The only dynamic variable here would be the number of servers that have each cron in their crontab. The other entries of N or Y should be static amongst each individual cron job as they are all setup the same way. The only thing that varies amongst the same cron job on each server is the time it executes, but since we're just adding a Y or N that's of no consequence.
Edit:
Here's the output of the latest version of the script with the missing bits added in to get it to display right:
$ ruby parse3.rb
Minutes Hours DayOfMonth Month DayOfWeek
min = Y, hour = N, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = N, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = N, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = N, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = N, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
min = Y, hour = Y, day of month = N, month = N, day of week = N
And here's the code:
#!/usr/bin/ruby
def doYorN(part)
if part == "*"
"N"
else
"Y"
end
end
file = File.new("cn.log", "r")
puts "Minutes Hours DayOfMonth Month DayOfWeek"
while (line = file.gets)
parts = line.split(' ')
puts "min = #{doYorN(parts[0])}, hour = #{doYorN(parts[1])}, day of month = #{doYorN(parts[2])}, month = #{doYorN(parts[3])}, day of week = #{doYorN(parts[4])}"
end
file.close
Last edited by Striketh (2011-11-08 23:42:30)