ITandME blog


Cron This!

Cron jobs are to Linux what Scheduled Tasks are to Windows. Users on a Linux system have the ability to create cron jobs and store them in their crontab. As with anything else in Linux a users crontab is just a file, but it's accessed, viewed, and edited a little differently and has a particular syntax for tasks to run properly. Here's a an example:



		# crontab -l
		...
		# m h  dom mon dow   command
		  0 0   *   *   *    /full/path/to/some/script.sh
		...
		

This is an example of listing your current accounts crontab on a Debian system. Other Linux distros might show something like this:



		# *     *     *     *     *        command to be executed
		# -     -     -     -     -
		# |     |     |     |     |
		# |     |     |     |     +----- day of week (0 - 6) (Sunday=0)
		# |     |     |     +------- month (1 - 12)
		# |     |     +--------- day (1 - 31)
		# |     +----------- hour (0 - 23)
		# +------------- min (0 - 59)
		#
		  30     18     *     *     *         rm /home/someuser/tmp/*
		

I think this does a pretty good describing how the syntax works with a few caveats.

A * means that entry is unset.

You can set fractions of entries using a / (good for seconds)

There are many other ways of using Crontab to edit entries, but I'll leave them alone for now and link a few pages I've referenced in the past:

http://www.adminschoice.com/crontab-quick-reference

Here's a Bash one-liner I've used in to comb through all the user crontabs on a system:



		for j in $(cat /etc/passwd | awk -F ':' '{print $1}'); do crontab -u $j -l; echo; done
		

HOME