This is the blog I m going to write to my followers who are a bit lazy.................
Suppose you have a server with you and you have to make the backup frequently on the same machine or some other on the network ..think how to monotonous job this is ????
Don't worry solution is here...you can schedule your system to make the backup of your data according to the time you mention.....this is cron scheduling
For doing so you have to change your crontab file in the directory /etc
You are to do as follow.....
1. Open your terminal
2. and type the command login as root user
3. check for the file 'etc/cron.allow' & '/etc/cron.deny' in case of some system it may be 'etc/cro.d/cron.allow' & '/etc/cron.d/cron.deny'
cron.allow contains the names of the user allowed to schedule the cron jobs and ..
cron.deny contains the names of the user which are not allowed to schedule the cron jobs
If none of the file exist then the root is the only user which can schedule the jobs
4. If you want to add some user to schedule the cron jobs then add the name of that user in the cron.allow file same for denying the user add them in the cron.deny file by using the following command it depends on you which editor you use (as my favorite editor is 'vim')..
~/# vi /etc/cron.allow
and simply add the list of user you want to allow one user in a line
5. After this you can schedule the job by using the one of the user in the cron.allow file or which are not in allow.deny (but I will show you below by root user).
6. Now write the command as below to schedule the cron jobs...
~/# vi /etc/crontab (You may use your favorite editor )
You will see on screen as in image....
In the above figure the commented part is not of over interest....the part of interest is from the line 'SHELL=/bin/sh'
It specify the default shell
The line next to it is to set the default variable 'PATH'
Now most important part of over requirement starts
Here commented line work as the heading for each element in the next line which have the specfic meaning as...
m for minute between 0 and 59
h for hour between 0 and 11
dom for day of month between 1 and 31
mon for month between 1 and 12
dow for day of week between 0 and 7, sunday is represented by 0 or 7, monday by 1, etc ...
user the command is to be run as a user
command to execute the command
for specifying the time we replace the corresponding '*'with the required digit
for example
we want to schedule our system to copy the file named index.php from dir /var/www/index.php to /home every hour
then add a line to crontab as..
0 * * * * root cp /var/www/index.php /home
for daily at 0800hr write as
* 08 * * *
if you want to run the command every minute the write as
* * * * *
apart from it there are some special character also
- for specifying the range
, for specifying the different values
/ for specifying the rate
examples
* * 1-15 * * it runs the command first fifteen days of months
10,12,13 * * * * it runs the command at 10th,12th and 13th minute of each hour
*/5 * * * * it runs the command every five minute
Instead of five stars you may use string to save your time which have the similar meaning to stars as below..
String Action
@reboot execution at boot
@yearly execution once a year, "0 0 1 1 *"
@annually execution once a year, "0 0 1 1 *"
@monthly execution onnce a month, "0 0 1 * *"
@weekly execution once a week, "0 0 * * 0"
@daily execution once a day, "0 0 * * *"
@midnight execution once a day, "0 0 * * *"
@hourly execution once an hour, "0 * * * *"
all the cron send the mail to you account about the output details of the command execution so to stop the mail append the following behind you cron command '>/dev/null 2>&1'
example:
0 * * * * root cp /var/www/index.php /home >/dev/null 2>&1
To send the email to some other user for example sachinnain0@nixcraft.in do as below
MAILTO=sachinnain0@nixcraft.in
0 * * * * root cp /var/www/index.php /home >/dev/null 2>&1
7. Now save you file and restart the cron by using the command
~/# /etc/init.d/crond/restart
there are some useful command for cron as
~/#crontab -e to edit the crontab file as we did above using the vim editor
~/#crontab -l list all your crontab jobs
~/#crontab -u username -l to list the all jobs for specified user
~/#crontab -r to remove all the cron jobs
~/#crontab -r -u username to remove all the cron jobs for specified users
This is all about the cron scheduling so use it to avoid the boredom as well as time waste.......



