Date Tags cron

I was trying to explain my system of crontabs to someone on IRC today and didn't put it over very well. So this is my attempt at improving it. I have a users.crontab and a root.crontab both in my cron folder in my home folder. The users crontab looks like this;-

#mean = 45 minutes, 19 hours, 26 day, 2nd month, any day of week
 #1 Minute 0-59
 #2 Hour 0-23 (0 = midnight)
 #3 Day 1-31
 #4 Month 1-12
 #5 Weekday 0-6 (0 = Sunday)
 #or
 # Min Hour DoM Month DoW Command
 */15 * * * * /home/boztu/cron/uptime.sh>>/home/boztu/cron/uptime.txt 2>&1
 00 */3 * * * /home/boztu/cron/backup.sh

The first seven lines are commented out and are there just to remind me of various things. Then we get to the line which starts off with '*/15' which shows that it runs every fifteen minutes and is calling a file called 'uptime.sh' and then pipes its output to a file called 'uptime.txt' in the cron folder, and its being continuosly added to as well. The second line beginning with '00' is running a file called backup.sh every three hours. I have already discussed this backup.sh on the 9th June.

When this is saved in the cron folder it is activated by this line -

crontab -u boztu /home/boztu/cron/boztu.crontab

Uptime.sh looks like this -

1
2
3
4
#!/bin/bash -x
 #shell script for use with uptime in user crontab
 date
 uptime

The 'root.crontab' looks like this -

##crontab for root
 # Min Hour DoM Month DoW Command
 30 4 * * 0 /usr/bin/apt-get clean
 30 5,17 * * * /usr/bin/apt-get update
 00 6,18 * * * /usr/bin/apt-get upgrade>/home/boztu/cron/apt-get.txt

The first two lines are commented out, with the second line just to remind me of the syntax for setting up new cron jobs.

The line beginning '30 4 ...' shows that at 0430 every Sunday morning apt-get clean runs and tidies up my cache file. The next line works at 0530 and 1730 and does an apt-get update to freshen the cache ready for the apt-get upgrade which is on the next line and runs at 0600 and 1800, and pipes its output to apt-get.txt. This is a once only file and is overwritten the next time its run, as shown by the > between 'upgrade> and /home/boztu.

The root.crontab is activated by this line -

sudo crontab -u root /home/boztu/cron/root.crontab

and then you just sit back and watch things happen as various cron jobs take place. I find that doing my crontabs like this makes things simpler for me and more understandable and controllable.



Comments

comments powered by Disqus