Crontab

In the old days, crontab was difficult. Right now it's not more than complicated... But in a simple manner.

If you want programs to run at specific times or intervals, you can instruct Linux to do that for you. Yes, any user can do that. Each one has his own crontab file. And there are two ways to do things.

Traditional crontab

The traditional method to do things is by issuing the command 'crontab -e'. You immediately get punished for that after pressing 'Enter': the system treats you on a 'vi' session.

Modern times crontab

Time has not been sitting still. No, time has been slipping in the past (from the future). According to the Steve Miller band, time keeps on slipping into the future. I say: that's wrong. Time comes from the future and slips into the past. The future is new time. Unmarked by humans and nature. The past is stamped time. It has been trodden on by people and nature has erupted on it.

And we use the new crontab to automate our trodding of fresh time. The new crontab file looks like this (the red colour is mine):

	# If you don't want the output of a cron job mailed to you, you have to direct
	# any output to /dev/null.  We'll do this here since these jobs should run
	# properly on a newly installed system, but if they don't the average newbie
	# might get quite perplexed about getting strange mail every 5 minutes. :^)
	#
	# Run the hourly, daily, weekly, and monthly cron jobs.
	# Jobs that need different timing may be entered into the crontab as before,
	# but most really don't need greater granularity than this.  If the exact
	# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
	# needs, feel free to adjust them.
	#
	# Run hourly cron jobs at 17 minutes after the hour:
	17 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
	#
	# Run daily cron jobs at 21:40 every day:
	40 21 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
	#
	# Run weekly cron jobs at 22:30 on the first day of the week:
	30 22 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
	#
	# Run monthly cron jobs at 20:20 on the first day of the month:
	20 20 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
	~
	~
	~
	~
	Read /var/spool/cron/crontab.3960, 22 lines, 1100 chars
   
The red lines are the only lines of importance to crontab. Their meaning is:
Of course we still don't know WHAT will be run. Well, that's easy. Everything is run! As long as the file is executable and is inside the directory specified as argument to the crontab line. So, the daily tasks need to be parked in the directory '/etc/cron.daily/'. In this case, the directory looks like the picture on the right.

See the tildes, lined up in the left side of the screen? That's a sign you are in 'vi', 'vim' or 'elvis'. You won't get out of this editor, unless you can get into beepmode and then you need to enter some magic spell:

  1. Get into BEEP mode by pressing the ESC key three or four times.
  2. Now enter ':q!' without the quotes.
Some non-vi editors omit the beeping of BEEP mode, to make things worse.....


Page created on 10 March 2009,

Page equipped with FroogleBuster technology