I just setup a cron to restart 'Thin' application server for my Ruby application every hour. I have tried every method but the cron is giving error saying command not found.  My script looks something like this  #!/bin/sh cd /var/www/myapp thin restart -C /etc/thin/myapp   (thinrunner is the name of the above bash script) crontab looks like this  0 * * * * /usr/local/bin/thinrunner   The error i get in email sent by crontab looks like this:  /usr/local/bin/thinrunner: 3: /usr/local/bin/thinrunner: thin: not found   I have also tried running it directly without creating a bash file but it says thin not found even then. I used the following to run directly  0 * * * * cd /var/www/myapp &amp;&amp; thin restart -C /etc/thin/myapp   I have already done chmod +x thinrunner and when i run the script directly, it works as expected. So what could i be doing wrong?   thanks
11012
Often, crontab scripts are not executed on schedule or as expected. There are numerous reasons for that:   wrong crontab notation permissions problem environment variables   This community wiki aims to aggregate the top reasons for crontab scripts not being executed as expected. Write each reason in a separate answer.  Please include one reason per answer - details about why it's not executed - and fix(es) for that one reason.  Please write only cron-specific issues, e.g. commands that execute as expected from the shell but execute erroneously by cron.
36900
The following command works from prompt but not from crontab.   grep abc  /var/log/messages | grep "`date '+%B %d'`" | mail -s"abc log of `hostname`" shantanu.oak+`hostname`@gmail.com   I need to add it to daily cron.
116101
Is there a way to indicate to  how/where to find (paths to)  tools such as python, nmap, php and so on?  I ask this because when I schedule a job using crontab -e, I always need to specify the full path of python, nmap and whatever other tool I want to use.
92130
I have created a script to install two scripts on to the crontab.   #!/bin/bash   sudo crontab -l &gt; mycron  #echo new cron into cron file   echo "*/05 * * * * bash /mnt/md0/capture/delete_old_pcap.sh" &gt;&gt; mycron #schedule the delete script  echo "*/12 * * * * bash  /mnt/md0/capture/merge_pcap.sh" &gt;&gt; mycron     #schedule the merge script  #install new cron file  crontab mycron rm mycron   The script runs, and add the two lines to the crontab. But if I run the script again, it adds those lines again , thus I will have four lines saying the same stuff. I want the install script to run such that, the lines inserted to the crontab do not repeat. How can I do that
74016
Trying to set up a daily cron job to shut down a server.   One source suggests editing /etc/crontab  Another suggests crontab -e (with sudo)  I tried the latter, and my process did not run (if I recall, it was 30 23 * * * shutdown -h)   I also note that in the nano editor, it was working on a .tmp file? (top of nano says: /tmp/crontab.9zeTNt/crontab )  What is going on? How can I fix this?
92777
I have a backup script which I need to run at a particular time of a day so I am using cron for this task and from within cron am also trying to redirect the output of backup script to a logfile.  crontab -e  */1 * * * * /home/ranveer/backup.sh &amp;&gt;&gt; /home/ranveer/backup.log   In the above cron entry I am redirecting both stderr and stdout to a log file.  The above cron job executes fine according to syslog  and it performs the task mentioned in the backup.sh file but it doesn't write anything to the log file.  /var/log/syslog  Oct 19 20:26:01 ranveer CRON[15214]: (ranveer) CMD (/home/ranveer/backup.sh &amp;&gt;&gt; /home/ranveer/backup.log)   When I run the script from cli it works as required and output is written to a log file  ranveer@ranveer:~$ ./backup.sh &amp;&gt;&gt; backup.log  ranveer@ranveer:~$ cat backup.log Fri Oct 19 20:28:01 IST 2012 successfully copied testdir test.txt successfully copied ------------------------------------------------------------------------------------- ranveer@ranveer:~$    So, why the output of file is not getting redirected to the file from within cron.
16964
I'm on OSX Snow Leopard.  Here's the full contents of grr.sh:  #!/bin/sh  echo wow   When I try to run it from terminal:  $ grr.sh -bash: grr.sh: command not found $ /bin/sh grr.sh wow $ sh grr.sh wow $ bash grr.sh wow   Okay. Fair enough. I'll give it executable permission, then try again:  $ chmod +x grr.sh $ grr.sh -bash: grr.sh: command not found $ chmod 755 grr.sh $ grr.sh -bash: grr.sh: command not found   Hmmm. Maybe it'll work if I use bash explicitly? I'll change the file's contents to:  #!/bin/bash  echo wow   And I get the exact same results. What could I have broken?!  One last thing! In case you're curious...  $ which sh /bin/sh
98912
test.sh: /usr/bin/notify-send "test"  The following works: bash ~/Documents/test.sh  BUT the crontab never shows the notification. Why?  */1 * * * * bash ~/Documents/test.sh
20861
I have an Automator workflow and one of the actions is to clone a repository. Here's the code for the 'Run Shell Script' action. The command is run within the Bash shell /bin/bash if that matters:  SOURCEDIR="${3/\/Volumes/}"  cd "$2" REPOURL="bob@somedomain.com:$SOURCEDIR" WORKINGDIR="$1"  # Capture any errors with cloning process in log file git clone "$REPOURL" "$WORKINGDIR" &amp;&gt; ./log.txt  // For debugging echo "exit code: $?" echo "PPID: $PPID"  open .   Now the Automator App runs fine on my machine. The path to git on my machine (A Macbook Pro) is: /usr/bin/git (I believe I installed git on my machine through Xcode)  But on my co-worker's machine (Also a Mac Pro) the Automator App fails. In fact, the output of the log.txt file says: bash: git: command not found   Now on my co-worker's machine the path to git is: usr/local/git/bin, which, yes, is different because he installed git through the Google Git Installer for Mac OS X, but I didn't think it should matter because in the script the git command is not absolute path to the command and further more my co-worker can run git normally from a Bash script but when invoked directly from the Terminal.  So what gives? Why does the automator workflow work for me but not for my co-worker?  There must be something fundamental about Bash or Unix that I'm not understanding here but I'm lost.
13012
I have a few cleanup commands to run for my datacaching scheme.  I was thinking a bash script would be an easy way to check if the full clean up job needed to be run.  But the cache is very time sensitive, so the check script needs to run every second.  What's the best way to do this?  Crontab only goes down to minutes, which makes sense for most applications.  Can I install a bash script as a background service?  On second though, can I just start it with the &amp; command and make it loop forever with a one second sleep?
16152
I want to edit my crontab file to schedule a script. Where do I find it?
93422
I tried to set up a root cron job to run a Bash script as root, to run at minute 7,37, every hour, every day of month, every month. This script is located in /usr/bin and named tunlrupdate.sh. It updates the DNS of Tunlr.  $ ls -l /usr/bin/tunlrupdate.sh  -rwxr-xr-x 1 root root 2133 Sep 24 15:42 /usr/bin/tunlrupdate.sh   This Bash script is available .  When invoked the script writes what's happening in a log located in /var/log/tunlr.log  To add this root cron job I used the standard for root's crontab  sudo crontab -e   And inserted these 2 lines at the end. I expect cron to run the script as root.  # check for updated Tunlr DNS every 30 minutes at the hour + 7 mn and hour + 37 mn 07,37 * * * * root /usr/bin/tunlrupdate.sh   A later command sudo crontab -l confirmed that the cron job has been inserted.  I did reboot Ubuntu and was checking in the log file if the cron job was launched properly. However there is nothing in the logfile /var/log/tunlr.log meaning the job was never successfully launched.  I did check that if I run the script from the command line  sudo /usr/bin/tunlrupdate.sh   then the logfile is updated accordingly.  Why is this cron job not running as planned in my system?  UPDATE 1 : All the proposed solutions so far do not work. I thank Olli for a CLI to list the system log sudo grep CRON /var/log/syslog. However I did get a CRON error  CRON[13092]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] &amp;&amp; [ -d /var/lib/php5 ] &amp;&amp; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php /maxlifetime) ! -execdir fuser -s {} 2&gt;/dev/null \; -delete)   with the suggested PATH= insertion &amp; use of absolute path from root for functions in the script or without this suggested solutions here. I still get this error.  After some searching I pinpointed the error in the file /usr/lib/php5/maxlifetime as is explained : Change #!/bin/sh -e --&gt; #!/bin/sh -x  Then listing the CRON error log in my system  sudo grep CRON /var/log/syslog Feb 11 18:07:01 Marius-PC CRON[14067]: (root) CMD (root /usr/bin/tunlrupdate.sh) Feb 11 18:07:01 Marius-PC CRON[14066]: (root) MAIL (mailed 1 byte of output; but got status 0x00ff, #012)   I still don't get the bash script executing. This time no error is shown in the log. To get assurance this was not the content of the script I reduced the script to the following 3 lines:  #!/bin/bash LOGFILE=/var/log/tunlr.log echo $LOGFILE &gt;&gt; $LOGFILE   I still don't get the cron job through. Nothing is written in the log file. So even may be an empty script will not run in cron ? I don't get it. I am know trying a script reduced to these 2 lines:  #!/bin/bash exit 0   And still the same error log. The cron script does not go through ...
49129
I've previously set a file to be crontab source file with crontab filename. How can I set it back to use default source? (the one that is modified with crontab -e)  Thank you.
51494
What's a simple way to run a command, say, 8 hours from now? I can think of this way:  nohup bash -c "sleep 28800 ; ./mycommand.sh" &amp;   Is there a more "proper" way?
82155
This is my script:  #!/bin/bash hd='pwd' cd $hd   When I try to run it, it fails with:  line 3: cd: $'pwd\r\r': No such file or directory   What is going on?
82471
I've installed a version of Ubuntu Server and although I'm fairly still fresh with Ubuntu, I'm trying to create a bash file to run a program in the background. More importantly, I'm trying to get a file nameto display correct and create it before I start running the program (I like my debug stuff).  However, here is my bash script:    #!/bin/bash  PATH="/var/log/servers/Game/"  FILENAME="startup"  EXT=".log"  DATE=$(date +%d-%m-%Y)  NEWFILE=${PATH}${FILENAME}_${DATE}${EXT}   I have verified that the file does exist in the PATH directory. However, the issue is with the date command. When I run the script bash -x game.sh this is what is displays.   + PATH=/var/log/servers/Game/  + FILENAME=startup  + EXT=.log  ++ date +%d-%m-%Y  game.sh: line 5: date: command not found  + DATE=  + NEWFILE=/var/log/servers/Game/startup_.log  + echo /var/log/servers/Game/startup_.log   I don't understand why it would say the command doesn't work, when I can go to the main console and run date and get a valid response.  Any help is greatly appreciated!
35519
Is there any way to make/run a bash script on reboot (like in Debian/Ubuntu for instance, since thats what my 2 boxes at home have)  Also, any recommended guides for doing cron jobs? I'm completely new to them (but they will be of great use)