Can't mount another server in crontab with 16.04

The cron program runs in a very limited environment - you can see that for example if you create a crontab containing

* * * * * /usr/bin/printenv > /tmp/cronenv

and then look at the resulting file:

$ cat /tmp/cronenv
LANGUAGE=en_CA:en
HOME=/home/steeldriver
LOGNAME=steeldriver
PATH=/usr/bin:/bin
LANG=en_CA.UTF-8
SHELL=/bin/sh
PWD=/home/steeldriver

The same applies to root crontabs (i.e. jobs submitted using sudo crontab -e):

LANGUAGE=en_CA:en
HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
LANG=en_CA.UTF-8
SHELL=/bin/sh
PWD=/root

In particular, the default PATH only contains /bin and /usr/bin; that would be fine for mount:

$ which mount
/bin/mount

however that won't work for mount.cifs for example, since it's in /usr/sbin:

$ which mount.cifs
/sbin/mount.cifs

The solution is either:

  1. always use the full absolute path for executable programs in scripts to be run as cron jobs; e.g.

    /usr/sbin/mount.cifs //192.168.1.200/share /media/SVR1 -o user=username,pass=pwd | tee -a ${LOGFILE}
    

or

  1. add a suitable PATH assignment at the top of such scripts e.g.

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    

NOTE: Jobs run from the system /etc/cron.d directory have a more extensive path set explicitly in /etc/crontab:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin