I != SysADMIN

I am very proudly not a sys admin I am so bad in fact I can't even spell it correctly. This of course has its disadvantages in the perl world where it seems every perl knows what this does.


ls | perl -pe 's!([^_]+)_(.)(.*)!mv $1_$2$3 \u$2\E$3!gio'

and at a YAPC I was the only one in the room that did not laugh at this


su root chmod 000 chmod 

I felt very left out.

Well call it my nature, as my natural skill set precludes sys-admin. I just find trying to remember all those commands I use once a year or even once in a job impossible for me. I have every respect for sys-admins I sort of see them like the surgeons of the tech-world, I know what they do and what they can do and I know I cannot do it half as well.

One task that I always spend too much time on is reading, correcting and entering cron entries. It seems simple enough but they always kill me. Where even the lowest grade sys-admin or junior programmer will see 'tue wed at 4 and 6 pm' I just a burble of meaningless '*', '-' and digits.

Well I think my long standing prayers have been answered by Bradley Andersen with his new mod 'ParseCron'.

Now I no longer have to run to wikipedia to look at the cron entry yet again to try and figure out what this means


22 4 * * 0 rdfsfdss rfdfdsfdsrts /etc/obstinate.pl
42 4 1 * * sfdsdfs rdfsfdss /etc/puge.pl
* 1,2,3,4 * * *  sfdsdfs rdfsfdss /etc/email_all.pl

Now I will just drop in the offending crons into in my 8 line perl program below


use strict;
use ParseCron qw/parse_cron/;
my $cron =ParseCron->new();
my @crons = ('22 4 * * 0','42 4 1 * *','* 1,2,3,4 * * *');
foreach my $value (@crons){
	my $readabe_by_john  = $cron->parse_cron($value);
	print $readabe_by_john."\n";
}
and I am of to the races

4:22am every Sunday
 4:42am on the first of every month
 Every minute of 1am, 2am, 3am, and 4am of every day

Opps I think I better go check that ' /etc/email_all.pl' program might explain the complaints from our users??

Anyway I can see this little gem coming in very handy.

Thanks again 'Bradley' if you ever see my at a YAPC I owe you 500g of Moose Jerky. Hopefully the one I bag this spring is a big one.

6a00d8345218da69e200e54f5f2c778833-500wi.jpg

2 Comments

Wrote a short script for you:

https://github.com/sharyanto/scripts/blob/master/humanize-crontab

Example usage on the command-line:

% crontab -l | humanize-crontab

Sample output:

# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.fcL9SL/crontab installed on Tue Nov 24 17:22:22 2009)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# m h  dom mon dow   command

MAILTO=steven@masterweb.net
SHELL=/bin/bash
PATH=/home/s1/bin/s:/home/s1/bin/mwn:/home/s1/bin/p:/home/s1/perl5/bin:/usr/bin:/bin

#0 12 * * * summarize-ical-files-to-log

# HUMAN TRANSLATION: 1:01am every day
1 1 * * * crontab -l >~/settings/crontab-pc-cyber

#4 4 * * 5 dl-solidot-week

# 2013-11-07
# HUMAN TRANSLATION: 6:06am every day
6 6 * * * count-my-todos >> ~/logs/todo-counts.log

# 2014-03-12 - seminggu 3x, kalo ada gagal parsing akan langsung direport by email, kalo error lain baru akan direport setelah 5x gagal berturut2
# HUMAN TRANSLATION: ERROR
30 18 * * Mon,Wed,Fri third-party-smoker ~/repos

# test
# HUMAN TRANSLATION: Every minute of every hour of every day
* * * * * ( printenv ; echo ) >> /tmp/env.log

So it seems ParseCron can't handle dow field in the form of dow names yet.

App::every comes in handy too.

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations