User Tools

Site Tools


cron

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cron [2012/02/08 13:50]
k2patel [Special Usage]
cron [2020/08/10 02:35] (current)
Line 27: Line 27:
 ==== Usage ==== ==== Usage ====
 Most common Usage terms defined as below. Most common Usage terms defined as below.
-<​note ​tip>when you use "​*"​ it consider all like "* * * * *" considered as every minute of 24/​7</​note>​+<​note>​when you use "​*"​ it consider all like "* * * * *" considered as every minute of 24/​7</​note>​
 <code bash> <code bash>
 # Minute ​  ​Hour ​  Day of Month       ​Month ​         Day of Week        Command ​   ​ # Minute ​  ​Hour ​  Day of Month       ​Month ​         Day of Week        Command ​   ​
Line 33: Line 33:
     0        2          12             ​* ​              ​0,​6 ​          /​bin/​sshcheck     0        2          12             ​* ​              ​0,​6 ​          /​bin/​sshcheck
 </​code>​ </​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.1328709051.txt.gz ยท Last modified: 2020/08/10 02:29 (external edit)