UNIX job scheduling commands :
In my previous articles, I have explained about different UNIX commands with real life examples. The scheduling job is also most important while working with UNIX. There are lot of situations where user needs to use scheduling in real examples. Scheduling specified task or job is most important in any operating system. There are two UNIX job scheduling commands; at and batch. UNIX supports one utility named CRONTAB to execute the cronjobs. In this article, I will try to give idea about different scheduling mechanisms in UNIX.
The Scheduling is the process of managing all the processes in operating system and running the processes at specific time.
at Command in UNIX:
at command is mostly used command to schedule specific task in UNIX operating system.at command run once to particular time that you normally give permission to run. You start by running the at command at the command line, passing it the scheduled time as the option. It then places you at a special prompt, where you can type in the command (or series of commands) to be run at the scheduled time. When you are done, press Control-D on a new line, and your command will be placed in the queue.
at date/time [interval] [task]
User can set up the command execution date and time. The execution time will be following:
The time should be 2 digit number for 24 hours clock (0-23).User can give the time directly in 4 digits in which first two digits will be in (0-23) range and other 2 digits will be in (0-59).User can give the time in AM/PM format also for 12-hour calendar. User will also use now, noon and midnight keywords.
User can schedule a job by giving specific date also. User can use the keywords like today, tomorrow or any day in the week to schedule specific task. The job will execute to soonest possible date. User will also use fully qualified date to schedule job. (E.g. 11 October 2018).
3.Manage Execution time :
User can manage the execution time by adding the incremental logic in command.User can insert the incremental logic by considering following keywords.
If user wants to execute some job 1 week later on current time then there is need to use +2 weeks incremental logic with at command.
Following are some important options with using at function
1.-f script :
The –f option is used to read the files from the specific file.
The –l option is used to queue the list of jobs.
-m option is another important option which is used to send the mail after job has finished.
4.-r (job number) :
This option will cancel the job whose ID is a job number. This option will work with at command.
Examples of UNIX job scheduling commands (at command) :
at Tuesday +2 hours /home/amit/scripts
Press: Ctrl + D
The job will run on each Tuesday after 2 hours of current time of scheduling.
at noon tar -cf /users/dvader dvader.tar
Press: Ctrl+ D
The job will run at noon the same day if submitted in the morning, or noon the next day if submitted in the afternoon. When the task is performed, a tarball of the /users/dvader directory will be created.
at -r amiet.b
Press : Ctrl + D
The above statement will delete job named amiet.b.
Crontab utility for UNIX job scheduling :
The crontab utility is used to execute asynchronous execute tasks at any desired time. In this article, I will just give the basic introduction about the crontab utility. Crontab is utility which is used to manage the tables that processes the tasks periodically.Crontab allows user who has right to add the jobs in system chronological tables.
1.crontab –e : This statement will allows user to edit their entries.
2.crontab –l : This statement will allow user to list current entries.
3.crontab –r :This statement will remove all entries for a given user.
The normal crontab entry will look like following:
Min Hour DOM MOY DOW Commands
DOM stands for Day of Month
MOY stands for Month of Year
DOW stands for Day of Week
Real Example :
Example 1 :
If user wants to run the some commands for daily 12 :30 AM time then following command will be used.
30 00 * * * /home/oracle/test_check.sh 2>>/dev/null
Example 2 :
If user wants to run command in each 5 mins.
There are following allowable values in crontab command :
Minutes : 0-59
Hours : 0-23
Day Of Month : 0-31
Month of Year : 1-12
Day of Week : 0-6 (by considering 0 as Sunday)
These 2 commands are mostly used commands for scheduling.Hope this article of UNIX job scheduling will be useful for everyone.Kindly do not forget to comment in comments section.