This was an interesting activity. This function is used if there is an activity that need to be done on an ongoing basis, for example, taking backups.
The cron utility resides in the /etc dir. Use the folling command to view cron files/dirs
ls -l /etc | grep cron
************The output*****************************
[root@new-host-5 ~]# ls -l /etc |grep cron
-rw-r--r-- 1 root root 329 Sep 28 2004 anacrontab
drwxr-xr-x 2 root root 4096 Apr 23 08:58 cron.d
drwxr-xr-x 2 root root 4096 Nov 2 18:25 cron.daily
-rw-r--r-- 1 root root 0 Nov 2 18:25 cron.deny
drwxr-xr-x 2 root root 4096 Sep 20 2004 cron.hourly
drwxr-xr-x 2 root root 4096 Nov 2 18:24 cron.monthly
-rw-r--r-- 1 root root 284 Apr 23 09:08 crontab
drwxr-xr-x 2 root root 4096 Nov 2 18:24 cron.weekly
*****************************************************************
check to see if cron is running;
ps -e | grep cron
Output will be;
[root@new-host-5 ~]# ps -e | grep cron
2224 ? 00:00:00 crond
***********************************************************************
To set up the cron job do the following;
crontab -e
This will open up the exiting cron jobs or it will be a blank file in vi.
Add the following lines;
15 16 * * 1-6 ~/backup.sh
15 => minutes after the set hour that the job will need to run.
16 => The hour the job will need to run.
* => days in the week the cron job will need to run (* represents all the days of the week)
* => Months of the year the cron job will need to run(* represents all the months of the year)
1-6 => The cron job will need to be executed from Mon - Sat
~/backup.sh => the script that needs to be run. Make sure that the script is executable (ie)chmod 755.
Thursday, April 24, 2008
Subscribe to:
Posts (Atom)