Sunday, April 23, 2017

How to set cronjobs ? Syntax and examples ?


crontab - maintain crontab files for individual users


How to get all list of crontab scheduled users on server

#ls /var/spool/cron/


files :-
/etc/crontab  >> is main file
/etc/cron.allow  >> who all have access to cronjobs
/etc/cron.deny >> who all doesnt have access to cronjobs

syntax :-


# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed


* * * * * root touch /tmp/file1

* means every minute/hour/dat of month/month/day of week


*/2  * * * * root touch /tmp/file1    means it will exicute every 2ms of every hour ,every day.

Below lets take example of minute

*/3 >> is every 3ms
3,5  >> at 3ms and 5ms
2-9  >> every 2ms,3ms---9ms.
 

No comments:

Post a Comment