Categories: Unix Tutorials

What is UNIX job scheduling commands |Crontab utility | at Command in unix

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.

Syntax:

at date/time [interval] [task]

User can set up the command execution date and time. The execution time will be following:

1.Time:

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.

2.Date:

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.

1.Minutes

2.hours

3.days

4.months

5.year

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.

2.-l :

The –l option is used to queue the list of jobs.

3.-m :

-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) :

Example 1:

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.

 

 

Example 2:

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.

Example 3:

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.

 Syntax :

The normal crontab entry will look like following:

Min Hour DOM MOY DOW Commands

Where :

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.

0,5,10,15,20,25,30,35,40,45,50,55****/usr/bin/amit

 

 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.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Share
Published by
Amit S

Recent Posts

The Essential Guide to Cryptocurrency Exchange Platform Development for Beginners and Beyond

Introduction Cryptocurrencies took the world by storm, setting up a new financial system and breaking…

5 months ago

Top 20 System Administrator Interview Questions and answers

In my previous article I have given Top 20 technical support interview questions with its…

8 months ago

Desktop Support Scenario Based Interview Questions

In my previous articles I have given 15 most asked desktop support interview questions with…

8 months ago

How Do Business Analysts Use SQL for Their Needs?

A business analyst is someone who is versed in processes of data analysis used for…

8 months ago

Top 15 Control-M Interview Questions with Answers

In my previous article I have already given top questions and answers for Desktop support…

8 months ago

Top 20 SQL Interview Questions for Production Support

In my previous article I have given unix production support interview questions and answers. In…

8 months ago