Friday, September 11, 2015

AtnCron

#This file has an information about AT & Cron sheduler

There are 2 shedulers --> AT & CRON

They allow to shedule a job
eg:- to poweroff a m/c at a particular time, to take a backup

Disadvantages of AT
1>We cannot run job repeatedly .
2>We cannot edit existing jobs .
3>If job is set for 7 o'clock and m/c is poweroff by chance, then it will not run that pending job of 7 o'clock. i.e; Once the time is passed it will not run that job

AT
The daemon required is 'atd'
#/etc/init.d/atd restart

To set a job in AT
#at now +1min
at>/bin/echo hi
at>ls -l
at>
Ctrl+D --> To save

#atq --> It will show job no. but not the output

output will go to mail it is not shown on screen

#atrm <job no.> --> To delete a job

#at now +5min
at>ls -l >> /root/job  --> to redirect a output to a particular file

#vi /etc/at.deny --> To deny users to set 'at' jobs



CRON

The daemon required is 'crond' -- by default it is in RAM
#/etc/init.d/crond restart

To set cron job for yourself
#crontab -e

Note:-- While writing any command in a script mention full path

#man 5 crontab --> To see the syntax of crontab

 The time and date fields are:

              field          allowed values
              -----          --------------
              minute         0-59
              hour           0-23
              day of month   1-31
              month          1-12 (or names, see below)
              day of week    0-7 (0 or 7 is Sun, or use names)
*     every

NOTE :--
1>Untill & unless o/p is not redirected to any terminal cron wil not o/p on screen, it will mail to root

2>Anacron daemon is watching cron job which are left out because of time {eg:- m/c is poweroff} After starting a m/c anacron will start that pending job

To set a job for user Jane so that he can view date at 1:05

#To assign a job on the basis of date command
##################################################

#crontab -e
min hour day-of- month day-of- command/script file/terminal
          month        week
30   11   *       *     *       /bin/date >> /root/date.txt


#ls /var/spool/cron  (entry is present in the /var/spool/location)

#on the basis of scripting
##############################

#vim ping.sh
ping -c 2 192.168.1.25 >> /root/ping.txt

#chmod +x ping.sh

#crontab -e
40 11 * * * /root/ping.sh




#crontab -u jane -e
-u --> user
-e --> edit

#vi /etc/crontab --> Crontab is set by system for itself
Various scripts are defined to run by system in a mentioned path eg:- /etc/cron.daily scripts are defined.

#cd /etc/cron.daily/
#ls
tmpwatch --> empty /tmp folder automatically


#crontab -e
* * * * * /bin/echo hi >> /dev/tty1

#crontab -l --> list cron jobs.

#crontab -r --> to remove cron jobs

#to allow or deny
######################
vim /etc/cron.allow

vim /etc/cron.deny


Note : Please refer Notes related to predefined cron jobs in /etc/cron.<>/ 

No comments:

Post a Comment

Linux Tables: Block All Incoming Traffic But Allow SSH

  This is very common scenario. You want to permit access to a remote machine only by SSH. You would like to block all incoming traffic to y...