



(8 ratings)
Few Tips On Cron :
To know what tasks cron shall be executing you can use the following command
$ crontab -l
This command shall provide a detailed list of all the jobs that cron shall execute. It would basically be showing you your crontab file. So you need to know the meaning of the 6 fields to make sense of the output
To remove the current crontab you can use the following command
$ crontab -r
This shall remove whatever entries you added to cron using your own crontab file.
To edit the crontab to enter or remove tasks type the following command
$ crontab -e
But note that typing this command would mostly open ' vi ' in order to edit the crontab file. And in case you are not familiar with vi then you would not like this behaviour. In that case open your crontab file (the one in which you entered all the tasks) using whichever text-editor you want, then add/remove the lines you want to, and then after saving the file run the following command
$ crontab [filename]
This will update the crontab with your new tasks. You can also check whether the update has taken place by typing the following command
$ crontab -l
If in a crontab file entry, the 'Day of Week' and 'Day of Mont' fields are both restricted (i.e. Both are NOT * ) then the task would be executed when either condition gets satisfied.
E.g. Day of month is 1-10 and Day of week is 3, then the task would be executed on the the first 10 days of the month and thereafter on every Wednesday that occurs in the month.
To run a task every 5 hours
If you want to do the above then in the crontab file entry, in the hour field you can enter a Step Value as follows '*/5' (without the inverted commas). This would cause the task to be executed every 5 hours.
To run a task in the first 10 days of a month and then last 10 days of the month you can use Ranges as follows
Enter '1-10,21-30' (without the inverted commas) in the 'Days' field.
To run a task every alternate day for the first 15 days of the month you can enter '1-15/2' in the 'Days' field. This would run the task on the following days of the month (1,3,5,7,9,11,13,15)
If you want to enter Comments, all you have to do is to add a # at the beginning of the line. Remember comments are not allowed on the same line with a cron command. So comments need to be entered on a separate line starting with a # (first character should be #)
This tip is important for all those countries that use daylight saving techniques. If a particular instant of time (when a task was to be executed) is lost because of changing the time for daylight saving then cron will simply skip that task and wait for the next occurrence of that particular time. Similarly if a particular instant of time occurs twice because of change in timing, then cron would once again execute that task a second time.
Besides comments and cron commands you can also make environment setting in the crontab file. In case the program that you would be executing requires any environment variables to be set, than those too can be set in the file that cron would use. An environment setting can be simply made using a name=value pair.
E.g. typing HOME=/home/david/myprograms on a separate line in the crontab file would make that particular directory your HOME directory.
20 Random Tutorials from the same category :
A Quick Introduction to Bash Programming - Part 2
Redirection in Linux
Compiling A Single-Source "C" Program
Windows COM Ports equivalent in Linux
How to find - Size of a directory & Free disk space
Linux keyboard shortcuts
Linux XP - a joke becoming reality?
About your files on Linux
Getting LILO to boot Windows (by default)
Viewing and searching the man pages
Manipulating files in Linux
Accessing User Information On A Unix System
Moving around in the Linux file system
How to edit and understand /etc/fstab
How and when to use the dd command?
Accessing CDROMs in Linux (covers mount, umount, fstab configuration file)
Asking questions in a discussion forum
Installing software from source in Linux
Installing software from RPM packages
Introduction To Unix Signals Programming













