User Tools

Site Tools


cron

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
cron [2012/02/08 13:38]
k2patel created
cron [2020/08/10 02:35] (current)
Line 4: Line 4:
  
 ==== Special Usage ==== ==== Special Usage ====
 +Following Special words replaces common conventional usage
 +
 <code bash> <code bash>
 @reboot ​       #Run once, at startup. @reboot ​       #Run once, at startup.
Line 14: Line 16:
 @hourly ​       #Run once an hour, "0 * * * *". @hourly ​       #Run once an hour, "0 * * * *".
 </​code>​ </​code>​
 +
 +Following variables you can define in cron as standard environment.
 +<code bash>
 +SHELL=/​bin/​bash
 +PATH=/​sbin:/​bin:/​usr/​sbin:/​usr/​bin
 +MAILTO=root
 +HOME=/
 +</​code>​
 +
 +==== Usage ====
 +Most common Usage terms defined as below.
 +<​note>​when you use "​*"​ it consider all like "* * * * *" considered as every minute of 24/​7</​note>​
 +<code bash>
 +# Minute ​  ​Hour ​  Day of Month       ​Month ​         Day of Week        Command ​   ​
 +# (0-59) ​ (0-23) ​    ​(1-31) ​   (1-12 or Jan-Dec) ​ (0-6 or Sun-Sat) ​               ​
 +    0        2          12             ​* ​              ​0,​6 ​          /​bin/​sshcheck
 +</​code>​
 +
 +Also most of the time you might want to disable logging the output of commands or scripts you are running.\\
 +Which can be used as follow.
 +
 +<code bash>
 +0 3 * * * bin/​git_commit.sh >/​dev/​null 2>&1
 +</​code>​
 +
 +Also some time you want to store output to file. it use standard notation for redirect.\\
 +For Append **>>​**
 +For Overwrite **>**
 +
 +<code bash>
 +35 0 * * * /bin/bash /​home/​kpatel/​workspace/​backup.sh >> output.txt 2>&1
 +</​code>​
 +
 +==== Things need to know ====
 +
 +     ​* ​ When cron job is run from the users crontab it is executed as that user. It does not however source any files in the users home directory like their .cshrc or .bashrc or any other file. If you need cron to source (read) any file that your script will need you should do it from the script cron is calling. Setting paths, sourcing files, setting environment variables, etc.
 +  *     If the users account has a crontab but no useable shell in /etc/passwd then the cronjob will not run. You will have to give the account a shell for the crontab to run.
 +  *     If your cronjobs are not running check if the cron deamon is running. Then remember to check /​etc/​cron.allow and /​etc/​cron.deny files. If they exist then the user you want to be able to run jobs must be in /​etc/​cron.allow. You also might want to check if the /​etc/​security/​access.conf file exists. You might need to add your user in there.
 +  *     ​Crontab is not parsed for environmental substitutions. You can not use things like $PATH, $HOME, or ~/sbin. You can set things like MAILTO= or PATH= and other environment variables the /bin/sh shell uses.
 +  *     Cron does not deal with seconds so you can't have cronjob'​s going off in any time period dealing with seconds. Like a cronjob going off every 30 seconds.
 +  *     You can not use % in the command area. They will need to be escaped and if used with a command like the date command you can put it in backticks. Ex. `date +\%Y-\%m-\%d`
 +
 +[[ http://​www.pantz.org/​software/​cron/​croninfo.html | Things need to know pasted from ]]
cron.1328708338.txt.gz ยท Last modified: 2020/08/10 02:29 (external edit)