Scheduling the jobs usung "at" and "cron" :
cron: job runs multiple times
at: jobs runs only onetime.
cron:
syntax: crontab options
-e (edit/add (uses vi editor))
-l (list the jobs)
-r (remove all the jobs)
syntax: crontab -e
crontab -u user-name -e ( as root to configure a cron job for a specific user)
mins hrs dayofmonth month dayofweek task
0-59 0-23 1-31 1-12 0-6 cmd
ex:
45 08 * * * backup.sh
0 0 * * * script1.sh
*/5 * * * * mon02.sh
0 * * * * script2.sh
0 2 * * * automation.sh
00 8,18 * * * /sbin/reboot
30 9,17 10,20 * * /bin/rm -rf /tmp/*
00 9,17 * * 6 /bin/rm -rf /tmp/*
NOTE: crontab is a binary command, all normail users are having access permission on crontab
which crontab
1. user listed in /etc/cron.deny are not allowed to use crontab
2. user's listed in /etc/cron.allow are only allowed to use crontab and /etc/cron.deny file is ignored.
cron jobs are managed by the service "crond"
chkconfig --list crond ; service crond status ( Before RHEL7)
chkconfig crond on ; service crond restart ( Before RHEL7)
systemctl enable crond ; systemctl restart crond (RHEL7)
cron logs are available in, /var/log/cron
croh jobs are stored in, /var/spool/cron/$USERNAME
task:
1. configure a cron job as root , it runs daily at 5:30PM and executes /bin/rm -rf /tmp/*
2. configure a cron job as student , it runs daily at 12:30AM and executes /bin/echo hello
3. restrict "user1" user, to perform cron jobs ( create user1 for checking )
------------------------------------------------------------------
at: syntax: at options
now
now+10min
now+1day
5:00pm or 17:00
5:00am
23:59 12/31/2013
ex: at 23:59 12/31/2013
at> cmd
at> ctrl+d(to quit)
atq ... to list at jobs
atrm jobid .. to remove jobs
at -c jobid ( to see job details )
chkconfig --list atd
service atd status
"at" is a binary command, all normail users are having access permission on "at"
which at
1. user listed in /etc/at.deny are not allowed to use "at"
2. user's listed in /etc/at.allow are only allowed to use "at" and /etc/at.deny file is ignored.
task:
1. configure a at job as root , it runs at 31st December 2020 at 23:59 and executes /bin/echo hi
2. configure a at job as root , it runs today at 2:30AM and executes /bin/echo hello
cron: job runs multiple times
at: jobs runs only onetime.
cron:
syntax: crontab options
-e (edit/add (uses vi editor))
-l (list the jobs)
-r (remove all the jobs)
syntax: crontab -e
crontab -u user-name -e ( as root to configure a cron job for a specific user)
mins hrs dayofmonth month dayofweek task
0-59 0-23 1-31 1-12 0-6 cmd
ex:
45 08 * * * backup.sh
0 0 * * * script1.sh
*/5 * * * * mon02.sh
0 * * * * script2.sh
0 2 * * * automation.sh
00 8,18 * * * /sbin/reboot
30 9,17 10,20 * * /bin/rm -rf /tmp/*
00 9,17 * * 6 /bin/rm -rf /tmp/*
NOTE: crontab is a binary command, all normail users are having access permission on crontab
which crontab
1. user listed in /etc/cron.deny are not allowed to use crontab
2. user's listed in /etc/cron.allow are only allowed to use crontab and /etc/cron.deny file is ignored.
cron jobs are managed by the service "crond"
chkconfig --list crond ; service crond status ( Before RHEL7)
chkconfig crond on ; service crond restart ( Before RHEL7)
systemctl enable crond ; systemctl restart crond (RHEL7)
cron logs are available in, /var/log/cron
croh jobs are stored in, /var/spool/cron/$USERNAME
task:
1. configure a cron job as root , it runs daily at 5:30PM and executes /bin/rm -rf /tmp/*
2. configure a cron job as student , it runs daily at 12:30AM and executes /bin/echo hello
3. restrict "user1" user, to perform cron jobs ( create user1 for checking )
------------------------------------------------------------------
at: syntax: at options
now
now+10min
now+1day
5:00pm or 17:00
5:00am
23:59 12/31/2013
ex: at 23:59 12/31/2013
at> cmd
at> ctrl+d(to quit)
atq ... to list at jobs
atrm jobid .. to remove jobs
at -c jobid ( to see job details )
chkconfig --list atd
service atd status
"at" is a binary command, all normail users are having access permission on "at"
which at
1. user listed in /etc/at.deny are not allowed to use "at"
2. user's listed in /etc/at.allow are only allowed to use "at" and /etc/at.deny file is ignored.
task:
1. configure a at job as root , it runs at 31st December 2020 at 23:59 and executes /bin/echo hi
2. configure a at job as root , it runs today at 2:30AM and executes /bin/echo hello