New Install cant get Cron Working [solved]

This is a new install December 2018 update on Raspberry Pi Model2. I had install cron using
apt-get but after reading other posts, removed the apt version and install from the OSMC shop on kodi.

I have looked at this post:

but not solved my issue. Cron used to work on my old built (before I the SD card was corrupted and I used mpc as an alarm clock.
I am testing using this line:

20 49 * * 1-5 df -hT > /home/osmc/diskstats

Which works from the terminal and creates a file in ~ .
Cron service is running:

osmc@osmc:~$ sudo service cron status
● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-01-24 20:45:48 GMT; 11h ago
     Docs: man:cron(8)
 Main PID: 6291 (cron)
   CGroup: /system.slice/cron.service
           └─6291 /usr/sbin/cron -f

Jan 25 04:17:01 osmc CRON[8737]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 05:17:01 osmc CRON[9002]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 05:17:01 osmc CRON[9003]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 06:17:01 osmc CRON[9271]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 06:17:01 osmc CRON[9272]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 06:25:01 osmc CRON[9325]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 06:25:01 osmc CRON[9326]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
Jan 25 07:17:01 osmc CRON[9674]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 07:17:01 osmc CRON[9675]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 07:17:01 osmc CRON[9674]: pam_unix(cron:session): session closed for user root

I dont see entries for user osmc.
Should osmc be a member of group crontab?

Below is permissions for crontabs:
osmc@osmc:/var/spool/cron$ ls -l
total 4.0K
drwx-wx–T 2 root crontab 4.0K Jan 24 20:48 crontabs

I posted
grab logs

Thanks in advance

Post 12 from the other thread doesn’t solve your issue?

I’m looking very carefully at previous post and what I see in the journal ctl
are cron tasks executed as user osmc:

Apr 17 12:40:02 osmc CRON[1903]: (osmc) CMD (/home/osmc/Extras/wg++/update.sh &>/tmp/troubleshooting.log)

I edited my crontab to see if I can get mpc to play:

13 39 * * 1-5 /usr/bin/mpc play 1

What I see in journalctl is:
journalctl_COMM=cron

Jan 25 08:18:01 osmc cron[6291]: (osmc) RELOAD (crontabs/osmc)
Jan 25 08:19:01 osmc cron[6291]: (osmc) RELOAD (crontabs/osmc)
Jan 25 09:17:01 osmc CRON[10776]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 09:17:01 osmc CRON[10777]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 09:17:01 osmc CRON[10776]: pam_unix(cron:session): session closed for user root
Jan 25 10:17:01 osmc CRON[11090]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 10:17:01 osmc CRON[11091]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 10:17:01 osmc CRON[11090]: pam_unix(cron:session): session closed for user root
Jan 25 11:17:01 osmc CRON[11395]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 11:17:01 osmc CRON[11396]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 11:17:01 osmc CRON[11395]: pam_unix(cron:session): session closed for user root
Jan 25 12:17:01 osmc CRON[11708]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 12:17:01 osmc CRON[11709]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 12:17:01 osmc CRON[11708]: pam_unix(cron:session): session closed for user root
Jan 25 13:17:01 osmc CRON[11985]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 13:17:01 osmc CRON[11986]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 13:17:01 osmc CRON[11985]: pam_unix(cron:session): session closed for user root
Jan 25 13:35:01 osmc cron[6291]: (osmc) RELOAD (crontabs/osmc)
Jan 25 13:38:01 osmc cron[6291]: (osmc) RELOAD (crontabs/osmc)

The crontab is reloaded for osmc but no commands are executed.
As root user cron hourly and daily are working.

Not sure what to do next, thanks for your help.

Hi,

I would try running a script in cron, rather than the command; so:

nano /home/osmc/mpd.sh

#!/bin/bash
/usr/bin/mpc play 1

cdmod +x /home/osmc/mpd.sh

13 39 * * 1-5 /bin/bash /home/osmc/mpd.sh

Thanks Tom.

With cron you really need to use the fully qualified name for the command, since the path might not be what you expect. In this case it is /bin/df. It is also good practice to send stderr (error) messages somewhere, eg to the diskstats file.

Run crontab -l to see what’s there for user osmc.

I made a bash script as Tom suggested. In crontab -l

20 58 * * 1-5 /home/osmc/mpd.sh

mpd.sh is executble with 755 contents:

osmc@osmc:~$ cat mpd.sh
#!/bin/bash
/usr/bin/mpc play 1

Shell script executes from home with ./mpd.sh

When I look at journalctl I see:

Jan 25 19:17:01 osmc CRON[14005]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 19:17:01 osmc CRON[14006]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 19:17:02 osmc CRON[14005]: pam_unix(cron:session): session closed for user root
Jan 25 20:17:01 osmc CRON[14330]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 25 20:17:01 osmc CRON[14331]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 25 20:17:01 osmc CRON[14330]: pam_unix(cron:session): session closed for user root
Jan 25 20:52:01 osmc cron[6291]: (osmc) RELOAD (crontabs/osmc)
Jan 25 20:58:01 osmc cron[6291]: (osmc) RELOAD (crontabs/osmc)

At the appropriate time the crontab is reloaded but no CMD is shown, it makes me think
I have a permission problem

These are my permissions for /var/spool/cron/crontabs

root@osmc:/var/spool/cron/crontabs# ls -l
total 4
-rw------- 1 osmc crontab 1122 Jan 25 20:57 osmc
root@osmc:/var/spool/cron# ls -l
total 4
drwx-wx--T 2 root crontab 4096 Jan 25 21:18 crontabs

My apologies to the forum my crontab time is wrong format !!
Should be Minutes Hours
And I had Hours Minutes !!!
Marking as [SOLVED}
just another PEBCAK :slight_smile:

Edit:
It also looks like you can run commands if they are in the same User environment.
env (for user osmc shows that /usr/bin is included in PATH
So I tried these lines:

m h dom mon dow command

35 21 * * 1-5 mpc play 1
36 21 * * 1-5 mpc stop

And they work,

Thanks for all tthe help marked as [solved] to stop people reading