Schedule Tasking using "crontab" and "at"

Schedule Tasking

Why we need " Scheduling " ?

Schedule makes our life more comfortable. In day to day life or even our life time we have to follow a schedule (may be not). In the college or school there was a time table. Assume a day that all teachers are came to school (In my point of view that was the worst day ). So teachers were allocated a time period for conducting their lesson. According to that schedule they come to the class and do the lesson. No one need to go and remember it to them. Somehow, in a particular time period some action happen without any support of third parties.

In a computing field, specially system administration field "Schedule Tasking" is a major component.
In this session  gonna tell you about schedule tasking in redhat.

What are the main scheduled works (jobs) ? 

  1. Works which are done once             
  2. Works which are need to do in consecutive time period 
 So  first take a look at ,

Works which are done once  

For an example, there will be an external auditing in the company. So you are the sysadmin of the company and you are asked to create an account for that auditor tomorrow morning at 8 a.m and account should be expired within two months.
"create an account for that auditor tomorrow morning at 8 a.m" is a one time task. It is never gonna be continued.

Works which are need to do in consecutive time period

For an example, backup should be taken place in every day 11 am and 4 pm. 
"every day 11 am and 4 pm" this is a continues work (job). This should be every day , every month , every year. In simply, if you dead while working , it wont affect to this process.

In Linux based Operating Systems are used "Crontab" and "at" for schedule tasking.

 at

"at" is used to perform Works which are done once. 

If we want to add user at 8 am,

  # at 8:00
at > useradd -u 7000 paul  (to get a new line press enter)
at > groupadd -g 8000 HR (to close press crtl + D )
at >  ^D

result will mail to you. Use 24 hour time format.
  • use mail command to view mails.
  • use atq command to view "at queue".
  • use atrm commant to delete scheduled jobs.  
If we want to add user at 1 hour after now,

 # at now + 1hour
at > useradd -u 8000 sam (to get a new line press enter)
at > groupadd -g 9000 IT (to close press crtl + D )
at >  ^D


Crontab

This is used to perform works which are need to do in consecutive time period.
Crontab is a file. Every user have crontab.
First take a look at what is cronjob ? Cronjob is nothing but it is a scheduled work.
So crontab is a collection of cronjobs.
If we logged in to one user, we can edit its crontab.
Crontab files are stored in the /var/spool/cron directory in redhat based operating systems.

use crontab + e to edit crontabfile.



You need to follow above pattern.


*/1 * * * * <command-to-execute>  ---> command will execute in every single minute.
*/5 * * * * <command-to-execute>  ---> command will execute in every five minutes. 
30 14 * * * <command-to-execute>  ---> command will execute in every day 2.30 pm.
0,4,8 * * * * <command-to-execute> --> command will execute in 3 times in every hour.
0 */2 * * * <command-to-execute>  ---> command will execute in every two hours.
* * * * SUN <command-to-execute>  ---> command will execute in every Sunday.  


Use crontab + l to view crontab file
Use crontab + r to delete crontabs

lets talk about more in crontab in part 2.
 


Comments

Popular posts from this blog

Basic Configurations in Windows Server 2016 (2)

Interrupt the kernel to change the fstab - RHCSA

Controlling the boot process - RHCSA