Crontab doesn't work

I’m trying to use cron for automate a script execution. The script will update the EPG data for the live PVR tv. Thie script works properly when I execute manual, but I need to execute automatically, as I will not need to execute every X days manually.

So after install crontab (from the OSMC store and apt-get, I get the same result) I insert the following line in sudo crontab-e:

17 11 * * * home/osmc/Extras/wg++/update.sh

But the script doesn’t run. If I type service cron status I get:

* cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled)
   Active: active (running) since Mon 2017-04-17 09:46:19 CEST; 1h 51min ago
     Docs: man:cron(8)
 Main PID: 210 (cron)
   CGroup: /system.slice/cron.service
           `-210 /usr/sbin/cron -f

So cron seems to be running properly. If I type sudo journalctl _COMM=cron I get:

-- Logs begin at Mon 2017-04-17 09:46:19 CEST, end at Mon 2017-04-17 11:39:17 CEST. --
Apr 17 09:46:19 osmc cron[210]: (CRON) INFO (pidfile fd = 3)
Apr 17 09:46:19 osmc cron[210]: (CRON) INFO (Running @reboot jobs)
Apr 17 10:11:01 osmc cron[210]: (osmc) RELOAD (crontabs/osmc)
Apr 17 10:11:01 osmc CRON[831]: pam_unix(cron:session): session opened for user osmc by (uid=0)
Apr 17 10:11:01 osmc CRON[832]: (osmc) CMD (home/osmc/Extras/wg++/update.sh)
Apr 17 10:11:01 osmc CRON[831]: (CRON) info (No MTA installed, discarding output)
Apr 17 10:11:01 osmc CRON[831]: pam_unix(cron:session): session closed for user osmc
Apr 17 10:16:01 osmc cron[210]: (osmc) RELOAD (crontabs/osmc)
Apr 17 10:17:01 osmc CRON[871]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 17 10:17:01 osmc CRON[872]: pam_unix(cron:session): session opened for user osmc by (uid=0)
Apr 17 10:17:01 osmc CRON[874]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Apr 17 10:17:01 osmc CRON[873]: (osmc) CMD (home/osmc/Extras/wg++/update.sh)
Apr 17 10:17:02 osmc CRON[871]: pam_unix(cron:session): session closed for user root
Apr 17 11:01:14 osmc cron[1072]: (CRON) DEATH (can't lock /var/run/crond.pid, otherpid may be 210: Resource temporarily unavailable)
Apr 17 11:08:16 osmc cron[1095]: (CRON) DEATH (can't lock /var/run/crond.pid, otherpid may be 210: Resource temporarily unavailable)
Apr 17 11:08:22 osmc cron[1096]: (CRON) DEATH (can't open or create /var/run/crond.pid: Permission denied)
Apr 17 11:13:01 osmc CRON[1173]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 17 11:13:01 osmc CRON[1174]: (root) CMD (home/osmc/Extras/wg++/update.sh)
Apr 17 11:13:01 osmc CRON[1173]: (CRON) info (No MTA installed, discarding output)
Apr 17 11:13:01 osmc CRON[1173]: pam_unix(cron:session): session closed for user root
Apr 17 11:17:01 osmc CRON[1192]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 17 11:17:01 osmc CRON[1193]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

Can anyone help me to locate what I’m doing wrong? Thanks!

Is this copy/paste or you typed in here?
Becuase you are missing a / before home! Should be /home/osmc/

You were right, I forgot the “/”. But still putting it I get:

Apr 17 12:04:01 osmc CRON[1673]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 17 12:04:01 osmc CRON[1674]: (root) CMD (/home/osmc/Extras/wg++/update.sh)
Apr 17 12:04:01 osmc CRON[1673]: (CRON) info (No MTA installed, discarding output)
Apr 17 12:04:01 osmc CRON[1673]: pam_unix(cron:session): session closed for user root

Can be anything more wrong?

Add 2>&1 behind the command in crontab to see the output in the log

I’ve added it as /home/osmc/Extras/wg++/update.sh 2>&1, but doesn’t appear anything new in the log.

try instead of 2>&1 this &>/tmp/troubleshooting.log
also what is the content of update.sh?

The update.sh content is:

#!/bin/bash
cd home/osmc/Extras/wg++
mono home/osmc/Extras/wg++/bin/WebGrab+Plus.exe  "$(pwd)"

Basically it executes the Webrabber, and running it manually it works.

After replacing the line by 40 12 * * * /home/osmc/Extras/wg++/update.sh &>/tmp/troubleshooting.log, I have no file in /tmp/troubleshooting.log, and using sudo journalctl _COMM=cron I get the same result:

Apr 17 12:39:01 osmc cron[1652]: (osmc) RELOAD (crontabs/osmc)
Apr 17 12:40:02 osmc CRON[1902]: pam_unix(cron:session): session opened for user osmc by (uid=0)
Apr 17 12:40:02 osmc CRON[1903]: (osmc) CMD (/home/osmc/Extras/wg++/update.sh &>/tmp/troubleshooting.log)
Apr 17 12:40:02 osmc CRON[1902]: pam_unix(cron:session): session closed for user osmc

As you added the / in the cron entry, you are missing it in update.sh as well. The location you are using is invalid without the preceding /.

Yes, I had it wrong again (I forgot them because before I had the path as ~/Extras…, then I changed it for the full path). I corected it but stil doesn’t work.

The script is located in /home/osmc but is being run as a root process.

This is generally a bad idea and also carries the risk that the crontab environment for root will (almost certainly) be different from the environment for user osmc.

The OP needs to be sure that the job really needs to be run as root.

You must also use the complete path for the command mono, wherever it is located.

Finally now it is already working. Thanks to all of you!

Maybe someone has, or will have in the future, the same problem. The solution was:

  1. Start the path with “/” in crontab and update.sh.

  2. Type the “mono” location, in my case /usr/local/bin/mono

  3. Use the crontab -e for the user who will run the script (in my case the user OSMC, and not the Root user).

So the script finally was:

#!/bin/bash
cd /home/osmc/Extras/wg++
/usr/local/bin/mono /home/osmc/Extras/wg++/bin/WebGrab+Plus.exe  "$(pwd)"

and the crontab -e:

24 13 * * * /home/osmc/Extras/wg++/update.sh

1 Like