This evening I have been playing with cron for the first time, and have started experiencing strange results.  The script that I am trying to run is a watchdog that allows me to manage a couple other scripts with a web interface.  When I run the watchdog script from a shell, sudo ./watchdog.py it works fine every time, and starts the scripts it is supposed to.  When I add it to crotab, sudo crontab -e with the line */1 * * * * /home/user/watchdog.py, it does not start them, or they crash shortly after starting.  These scripts do need to run as root, so I have also tried */1 * * * * sudo /home/user/watchdog.py, but nothing changed.  My question is 2 part.  1:  How do I troubleshoot this?  2:  What causes this, and why?
589
This is a  about using cron &amp; crontab.   You have been directed here because the community is fairly sure that the answer to your question can be found below. If your question is not answered below then the answers will help you gather information that will help the community help you. This information should be edited into your original question.  The answer for 'Why is my crontab not working, and how can I troubleshoot it?' can be seen below.  This addresses the cron system with the crontab highlighted.
94968
For some reason, when I try to run any programs (I am trying to run a rootkit hunter: rkhunter) as root on the command line with sudo like this:  sudo rkhunter   Then I get this message:  You must be the root user to run this program   and then I get these lines:  sudo: error in /etc/sudo.conf, line 0 while loading plugin 'sudoers_policy' sudo: /usr/lib/sudo/sudoers.so must only be writable by owner sudo: fatal error, unable to load plugins   I try typing in just sudo but that comes up with the same three errors as above. Also in /etc/ sudo.conf does not exist.  I cannot run any other programs as root through sudo. It was also strange because I could run as root a day ago. I would like it to work.  Just so you know, I am the only user of this computer, and the administrator, running Lubuntu 14.04.1.
33396
Here's my source:  #!/bin/bash  echo "Running script to free general cached memory!" echo ""; echo "Script must be run as root!"; echo ""; echo "Clearing swap!"; swapoff -a &amp;&amp; swapon -a; echo ""; echo "Clear inodes and page file!"; echo 1 &gt; /proc/sys/vm/drop_caches; echo "";   It clears caches and stuff, and it echoes that it needs to be run as root in the terminal. I basically just want the script to cease running if it detects it's not being executed as root.   Example:  "Running script to free general cached memory!" "Warning: script must be run as root or with elevated privileges!" "Error: script not running as root or with sudo! Exiting..."   If run with elevated privileges, it just runs as normal. Any ideas? Thanks!
96679
I'm running on a couple of different Linux distros (Fedora 11, CentOS 5 and SuSE 10.2) and  often run into a problem where a new script that I want to run as a cron job works fine when called direct from the command line, but fails when called from cron due to slight variations in the PATH or other required environment variables.  Is there a way I can test run an individual script as if it's being run from cron, without having to run the entire crontab or use run-parts to run the entire cron.daily/ .hourly etc. directory ?  I guess I could temporarily edit my crontab to run the script in the next couple of minutes, but I'd rather have a more standalone solution so that I don't risk messing up the crontab.
109915
I have a CRONTAB entry as below. Can someone tell me what the below statement is exactly doing?  1 0 * * * /vol01/sites/provisioning/MNMS/45627/45627.sh1 &gt;&gt; /vol01/sites/provisioning/MNMS/45627/output/cron.log 2&gt;&amp;1
40322
I have a crontab that looks like  0 0 * * * pg_dump DB_NAME &gt; /path/to/dumps/`date +%Y%m%d`.dmp   which works fine when I run it manually, but not when cron runs it. After digging through the logs, I see  Dec 12 00:00:01 localhost crond[17638]: (postgres) CMD (pg_dump DB_NAME &gt; /path/to/dumps/`date +)   It looks like a problem with percent signs, but the man page doesn't even contain the percent character at all, so I thought they were alright.
67708
I have a unix installation that's supposed to be usable both as a chroot and as a standalone system. If it's running as a chroot, I don't want to run any service (cron, inetd, and so on), because they would conflict with the host system or be redundant.  How do I write a shell script that behaves differently depending on whether it's running in a chroot? My immediate need is a modern Linux system, with /proc mounted in the chroot, and the script is running as root, but more portable answers are welcome as well. (See  for the case of Linux without /proc.)  More generally, suggestions that work for other containment methods would be interesting. The practical question is, is this system supposed to be running any services? (The answer being no in a chroot, and yes in a full-fledged virtual machines; I don't know about intermediate cases such as jails or containers.)
33468
I did edit /etc/crontab using corntab -e. I have only one entry  After save contab is not created despite the message.  To be honest I have no idea what to do. I simply want to create a simple daily job. Second question. How can I change the editor for crontab -e?
99603
I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?
56576
I am using Ubuntu 14.04. I wrote a small script named trial. The contents of the script are as follows:   #!/bin/sh SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin      sh -c firefox   I copied the script to /etc/init.d, modified permission using chmod +x trial and used update-rc.d trial defaults. The file made link but when I rebooted the machine. It did not run firefox. I tried cron @reboot but with no success. I tried rc.local too again failure.
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?
27545
There is a Cron job on Ubuntu 16.04 which runs a PHP script  $parseinfo = 'parseme.json'; $handle = fopen($parseinfo, 'w'); fwrite($handle, json_encode($res));   to parse data into a JSON file. The PHP script is supposed to write data within the same folder where this PHP script is located in but I've faced a problem that JSON is being saved into root's home directory:    This is how I set Cron job:  */10 * * * *  root    /usr/bin/php    /var/www/somederictory/somefolder/parse.php &gt; /dev/null   From terminal:  ssh root@example.com cd /etc crontab -e :x   In short words: JSON is being saved into /root while I want it to be saved into /var/www/somederictory/somefolder/ What should I do to fix it?  Edit: It is not a duplicate, PHP works, JSON is being saved, but in a wrong way. And I'm asking to help me understand what's wrong with current Cron settings.
42578
Am trying to create a cron job to open a web page at a scheduled time.   I have edited my cron using crontab -e and append my job.  I wrote my job in a script like this: xdg-open (URL)  I saved this script in my /home/flicker directory.   However, when I edit my cron (crontab -e), it saves the file as /tmp/crontab.tIzXBv/crontab.   After saving it successfully says installing new crontab.   I made my file script executable, but still failing to handle the job.  I wanted the script to run at 14:30PM, so I added this line to my crontab:   30 14 * * * /home/flicker/open-web.sh   This is still failing to work please help. Here is my script below:  #!/bin/bash xdg-open https://www.google.com
25142
I would like to automate some services using cron jobs.  When I try to edit the crontab file at /etc/crontab, I am not able to save it as it says that it is read only.   What can I do?
5735
I must have a blind spot, but I cannot find what it is.   I made a small python script that removes VLC from the sound menu. It runs perfectly in any way I run it from the terminal or from a launcher or whatever you can think of.   What the script actually does is nothing more than get the get the current settings:  gsettings get com.canonical.indicator.sound interested-media-players   edit the list, and set the changed list by:  gsettings set com.canonical.indicator.sound interested-media-players "['newlist']"   These commands are executed by a python script,. However, when run from a cronjob (crontab -e) only the gsettings - get - part works, but not the gsettings - set - section. That the get section works fine with cron, I checked by making the script write data (the original as well as the edited) to an external file.  Not a python problem  To see if the problem is related to python code, I created a bash script that applies a changed sound menu items list. The story is the same: the bash script runs fine from the command line or a launcher, not from cron, while any other command in the same script would run fine. Also, if I add any command at the end of the script below, it works fine and it looks like the script is satisfied with its own work.  Why is the gsettings set command not working when initiated from cron?  This is the script:  #!/usr/bin/python3 import subprocess  def read_soundmenu():     # read the current launcher contents     get_menuitems = subprocess.Popen([         "gsettings", "get", "com.canonical.indicator.sound", "interested-media-players"         ], stdout=subprocess.PIPE)     return eval((get_menuitems.communicate()[0].decode("utf-8")))  def set_current_menu(current_list): # this takes no effect from cron     # preparing subprocess command string     current_list = str(current_list).replace(", ", ",")     subprocess.Popen([         "gsettings", "set", "com.canonical.indicator.sound", "interested-media-players",         current_list,         ])  current_list = read_soundmenu() for item in current_list:     if item == "vlc.desktop":         current_list.remove(item) set_current_menu(current_list)
1886
Running Cronjob @reboot returns that file on nfs share does not exist.  Example  @reboot python /abs/path/to/script.py   mail from crontab on startup reads "more or less"  /usr/bin/python can't open file "/abs/path/to/script.py": [Error No. 2] No such file or folder.   Script can be run from the command line with no trouble.. Theory is that the cronjob is running before mount has been run. The questions.   Is this theory correct? Is there a way to force the job to wail until the drive has been mounted? .... Other than just putting in a sleep 60 into the command. ;) I tried that already, but it's hit and miss and I need the script to run 100% of the time quickly.
104641
I have a deployment script, it must add something to a user crontab (trigger a script that clean logs every XXX days), however this must only be done during the first deployment, or when it needs to be updated.  (I can run xxx.py deploy env or xxx.py update env)  so I have to do this:  Check if my cronJob already exist Put my cronJob if it does not already exist or update my cronjob if one of the parameter of the command is different   I don't see how to add/check/remove something to the crontab without using crontab -e or editing the crontab file (download it, rewrite it, re-upload it)  PS : this is a user specific cronjob, "webadmin" is going to do it and he should not use sudo to do it.