Tuesday, April 12, 2011

Automated Tasks


                                             Automated Tasks

1] CRON :- It is a daemon to execute scheduled commands.
If we are having a script /home/sample.sh and we want to run it after every 2 minutes then,
There is a file in '/etc/crontab' Edit it and write there as,

*/2 * * * * sh /home/sample.sh

save and exit

Here

*/2 * * * * * command to be executed
-     - - -  - -
|     | | |  | |
|     | | |  |+- Year (optional)
|     | | | +----- day of week (0 - 6) (Sunday=0)
|     | | +---------- month (1 - 12)
|     | +--------------- day of month (1 - 31)
|    +-------------------- hour (0 - 23)
+------------------------- min (0 – 59)

Thus the script /home/sample.sh runs after every 2 minutes


If you want to run cron job by specific users then make a new file '/etc/cron.allow' and insert user names in it, those users which are allowed to set cron.
If user runs a cron jon then in “/var/spool/cron” directory there is a new file created by that users name. We can edit that file by “crontab” command.

i.e. $ crontab -e

to see scheduled cron, $ crontab -l
To restart service,
# service crond restart

To delete a job,

$ crontab -R (job no.)


                                       “at” Command

               This command Schedules other command (or job) to be ran at a particular time, such as a print job late at night.

“atq” : lists the user's pending jobs, unless the user is the superuser; in that case, everybody's jobs are listed. The format of the output lines (one for each job) is: Job number, date, hour, job class.

“atrm” : deletes jobs, identified by their job number.

You can check the other parameters for the command “at” by entering:
$ man at

Example :
 
$ at -m 02:50 < newatjob :  Run the commands listed in the 'newatjob' file at 2:50AM, in addition all output that is generated from job mail to the user running the task. When this command has been successfully enter you should receive a prompt similar to the below example.

                                    “batch” COMMAND
                   This command executes the other commands when system load levels permit; in other words, when the load average drops below 1.5, or the value specified in the invocation of atrun. It is similar to “at” in other respects.

No comments:

Post a Comment