Cron – Odd Crontab Service SMB Restart Issue

cronsambaservice

System: Debian Wheezy x86_64
Service: Samaba

When I'm in a terminal I can use service samba restart or /etc/init.d/samba restart to restart the service. When I create a cronjob and use /etc/init.d/samba status it works.

But when I try

/etc/init.d/samba restart

in crontab, I get the following report:

Stopping Samba daemons: nmbd/etc/init.d/samba: 119: start-stop-daemon: not found
smbd/etc/init.d/samba: 119: start-stop-daemon: not found
.
Starting Samba daemons: nmbd/etc/init.d/samba: 119: start-stop-daemon: not found
failed!

When tested all works fine, while in a terminal just not when the crontab runs it.

Samba service is up and running and working well after a few tweaks in smb.conf so I am just having the issue getting the crontab to restart it for me.

Best Answer

Your crontab should look like this:

0 * * * * /etc/init.d/samba restart >> /dev/null 2>&1

Also be sure you are sudo when editing this cron, eg. with:

sudo crontab -e