I've experienced an issue where some of my scripts run perfectly fine when I call them manually, but these same scripts when called as cron jobs via cron don't seem to work at all.  So my question: I'd like to know if there are restrictions that apply with the use of commands and/or scripts (and the privilege of execution) in a script scheduled to run with cron?
124009
I have a test.sh script  #!/bin/sh php /home/v/file.php sh /root/x/some.sh   when I execute the file as root from command line it works.  sh /home/v/test.sh    when I set it to crontab -e (is the root cron), is not working   * * * * * sh /home/v/test.sh   What do I do wrong? Thanks
92245
I want to be able to programatically add a new cron job, what is the best way to do this?  From , it seems I could dump the current crontab and then append a new one, piping that back into crontab:  (crontab -l ; echo "0 * * * * wget -O - -q http://www.example.com/cron.php") | crontab -   Is there a better way?
15217
I finally set up a realistic backup schedule on my data through a shell script, which are handled by cron on tight intervals. Unfortunately, I keep getting empty emails each time the CRON has been executed and not only when things go wrong.   Is it possible to only make CRON send emails when something goes wrong, ie. my TAR doesn't execute as intended?  Here's how my crontab is setup for the moment;  0 */2 * * * /bin/backup.sh 2&gt;&amp;1 | mail -s "Backup status" email@example.com   Thanks a lot!
37848
I am trying to automate the refreshing of awstats for my webserver and understand that I need to use cron to set that up.  So each user has a crontab file? I was following the instructions  community/AWStats And it says to go to the file at: /etc/crontab That file already has some information in it.  Is this the main crontab file or something?  I have seen some instructions online to use the file that pops up with crontab -e. What is the proper file to use and the best way to do this? If I schedule a task as my non-root user, will it run by itself at the time interval as specified, with no issues? Will I need to restart the server after saving the cron job in the crontab file before it will start working?
34673
I'm having a very weird error when trying to make a script callable. I have a scripts directory in /srv/projectname/scripts where I store you know scripts to be called as cron jobs for different projects. I'm trying at add a new one and seeing very weird behavior. In debugging I reproduce it using this set of commands  from /srv/projectname/scripts create a file create a file  vi helloworld.sh   insert text exactly:  #!/usr/bin/env bash  echo "Hello World!"   Make the script executable and try to call it:  chmod +x helloworld.sh ./helloworld.sh   Which gives:  -bash: ./helloworld.sh: Permission denied   Make sure there isn't a code error:  bash helloworld.sh   Which gives:  Hello World!   Copy the script to home and call it:  cp helloworld.sh ~/helloword.sh ~/helloword.sh   Which gives:  Hello World!   I have no idea what is going on. I have tried a lot of variants where I give the full path, same error, or if I sudo which gives no error, but also doesn't print "Hello World!".  Other details: Running on: Ubuntu 12.04.4 LTS I have also noticed that I can't tab-complete to the full name of a script that gives me this error, but I can once I have moved it. The directory /srv/projectname is a git repo but this script hasn't been added to it yet, I because I usually only do that once its working yet.  ls -l lines for the script and scripts directory are  -rwxrwxr-x 1 ubuntu ubuntu     41 Apr 21 20:25 helloworld.sh drwxrwxr-x 3 ubuntu ubuntu 4096 Apr 21 20:25 scripts   respectively   Any help would be awesome.  EDIT: Gilles had the answer. To save anyone else who has this problem a google search.  sudo mount /srv/projectname/ -o remount   reloads the edited fstab, and everything works again.
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)
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.
14452
Somehow, I am finding it difficult to understand tweaking around * parameters with cron.  I wanted a job to run every hour and I used the below setting:  * */1 * * *   But it does not seem to do the job. Could someone please explain the meaning of above and what is needed for the job?
76130
I have set up a cron job, but for some reason it fails to run during the night. The same job runs fine when i'm running it during the day (i.e. setting up the same job to run in a few minutes and waiting for it to run).  Some logs:  Jun 17 14:04:01 server CRON[20174]: (root) CMD (/home/server/scripts/sync.sh &gt;&gt; /home/server/logs/nightly.log 2&gt;&amp;1) Jun 17 14:12:01 server CRON[20349]: (root) CMD (/home/server/scripts/sync.sh &gt;&gt; /home/server/logs/nightly.log 2&gt;&amp;1) Jun 17 14:23:01 server CRON[20513]: (root) CMD (/home/server/scripts/sync.sh &gt;&gt; /home/server/logs/nightly.log 2&gt;&amp;1) Jun 18 01:00:01 server CRON[25717]: (root) CMD (/home/server/scripts/sync.sh &gt;&gt; /home/server/logs/nightly.log 2&gt;&amp;1) # this runs during the night Jun 18 01:00:01 server CRON[25706]: (CRON) error (grandchild #25717 failed with exit status 2) # doesn't leave anything behind it, not even the nightly.log file - as though the command itself is invalid)   cron entry looks like this:  0 1 * * * /home/server/scripts/sync.sh &gt;&gt; /home/server/logs/nightly.log 2&gt;&amp;1   script looks like this:  #!/bin/bash  SUCCESS=0 echo "Running nightly automation..." echo "Running xxxx script..." SUCCESS=`/home/server/scripts/xxxx.sh &amp;&amp; echo 1` if [ $SUCCESS -eq 1 ]; then         echo "xxxx success!" else         echo "xxxx fail!" fi echo "Running rsync..." /usr/bin/rsync -am --remove-source-files /path1/ /path2/ --log-file=/home/server/logs/sync.log &amp;&amp; echo "rsync success!"
62331
Here is a simple example showing that using declare in a script the script will not run, while sourcing the script will:  $ cat /tmp/new #! /bin/sh declare -i  hello $ chmod a+rwx /tmp/new $ /tmp/new /tmp/new: 3: declare: not found $ source /tmp/new $    I wonder why directly running the script doesn't work, while sourcing it does? How can I make the first one work? Thanks!
83920
I entered crontab -r instead of crontab -e and all my cron jobs have been removed.   What is the best way (or is there one) to recover those jobs?
44847
I tried to schedule a command to execute 2 minutes later  at -c "ls -l" now + 2 minutes  It fails with multiple ways  $ echo "open 'Google Chrome' " | at now + 2 minutes job 15 at Mon Oct 29 13:31:42 2018   How could I enable it working?  run "open 'Google Chrome' "  at now + 2 minutes   I tried, it is not working  $ at now  at&gt;ls -l at&gt;^D at&gt; &lt;EOT&gt;  job 18 at Mon Oct 29 15:55:00 2018
17920
I am looking for a simple and generic solution that would allow you to execute any script or application in crontab and prevent it from running twice.  The solution should be independent on the executed command.  I assume it should look like lock &amp;&amp; (command ; unlock) where lock will return false if there was another lock.  The second part would be like if it acquired the lock, run command and unlock after command is executed, even if it returns error.
104065
The Case: I need to run some commands/script at certain intervals of time and for this I have two options:  set up a cron-job implement a loop with sleep in the script itself.  Question: Which is the better option from resource consumption point of view, why? Is cron the better way? Does cron use some kind of triggers or something making it efficient over the other? What procedure does cron use to check and start the jobs?
18003
I was wondering if the following two ways of running a bash script are equivalent?  . ./myScript.sh  source myScript.sh  Are they both running the content of the script instead of running the script, i.e. not creating a subshell for running the script?
55825
How to execute a script periodically like crontab does but without using crontab?  Please note this that the executed script should not fire with another script and schedule it with 'sleep' command, what I expect to have same functionality as crontab but it should not be present in crontab list and should not be stop when terminal or session ended,   crontab exactly but without croning it.
92759
I'm trying to ensure a script remains running on a development server. It collates stats and provides a web service so it's supposed to persist, yet a few times a day, it dies off for unknown reasons. When we notice we just launch it again, but it's a pain in the rear and some users don't have permission (or the knowhow) to launch it up.  The programmer in me wants to spend a few hours getting to the bottom of the problem but the busy person in me thinks there must be an easy way to detect if an app is not running, and launch it again.  I know I could cron-script ps through grep:  ps -A | grep appname   But again, that's another hour of my life wasted on doing something that must already exist... Is there not a pre-made app that I can pass an executable (optionally with arguments) and that will keep a process running indefinitely?  In case it makes any difference, it's Ubuntu.