November 4, 2009

Tips and Tricks: Scheduling Jobs Without Cron in Linux: An Example on using the at command (or batch command)

Cron is one of the most widely used job schedulers in the *nix systems such as Linux. However one needs to add jobs in the crontab file to schedule the jobs and this is not possible (typically) for users without super user privileges (In my case I needed to schedule an scp from a remote machine at 03:00 from a machine in which I did not have super user priviliges).

For such users job scheduling is possible with the help of the at/batch command or (batch command).

An example for using the at command to schedule the executing of the file present at /tmp/ is as follows:

Create a file /tmp/ by executing the following command

#> echo "touch /tmp/abc.text" > /tmp/

#> chmod +x /tmp/

Make sure that the atd deamon is running, which is the daemon process that is responsible for scheduling the jobs.

#> ps -ef | grep atd

Now schedule the job at say 03:00 tomorrow

#> at -f /tmp/ 03:00 tomorrow

The output will be something like

job 1 at 2009-11-05 03:00

The process will execute /tmp/ at the given time. Do a 'man at' for a glimpse of the complex time specifications the batch/at command allows.

No comments: