Croncal – the Cron Calendar
The croncal
is a clever Perl script that reads entries in your crontab
and outputs a schedule, showing the time when cron jobs will run.
This can be useful when planning for server downtime, for example. You may want to know what cron jobs will fail to run and how many times. To download the script:
#!/bin/bash d=/var/adm/bin f=croncal.pl mkdir -p ${d} wget -O ${d}/${f} --no-check-certificate "https://raw.githubusercontent.com/waldner/croncal/master/${f}" chown root:root ${d}/${f} 2>/dev/null chmod 755 ${d}/${f} 2>/dev/null ln -s ${d}/${f} /usr/bin/croncal 2>/dev/null
To use
croncal
you need to specify three parameters: start time, end time, and the crontab file. The time must be entered in the following format: YYYY-mm-dd HH:MM
The following example will list all /var/spool/cron/root
cron jobs that will run on the server in the next hour:s=$(date -d 'now' +'%Y-%m-%d %H:%M') e=$(date -d 'now +1 hour' +'%Y-%m-%d %H:%M') croncal -s "${s}" -e "${e}" -f /var/spool/cron/root
Sample output:
2017-08-09 11:00|/opt/diskminder/diskminder_collector.sh >/dev/null 2>&1 2017-08-09 11:05|salt-run -t 60 manage.down 2>/dev/null | sed -e "s/[\[', ]//g" > /tmp/salt-minion-down 2017-08-09 11:20|/var/adm/bin/salt_master_status.sh >/dev/null 2>&1
Here’s another example: I am using
Salt
to count all cron jobs in /var/spool/cron
on all servers that run during the week:s=$(date -d 'last Monday' +'%Y-%m-%d 00:00') e=$(date -d 'next Monday' +'%Y-%m-%d 00:00') salt --output=txt "*" cmd.run "for i in `ls /var/spool/cron` ; do croncal -s \"${s}\" -e \"${e}\" -f /var/spool/cron/${i} 2>/dev/null; done" 2>/dev/null | wc -l
Sample output:
2030584
So the next time your boss says you need to automate more, tell him how many things are happening automatically already :)