0

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.

1
  • 1
    Better question: Why do you need to schedule restarts of the Samba daemon? – ewwhite Dec 18 '14 at 17:25
0

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
5
  • How does the >> /dev/null 2>&1 get the restart cmd to work while not using it the status will work, but the restart won't? – LinG33k Dec 18 '14 at 18:46
  • The main thing is that you need to adjust the sudo (root) crontab not your local user cron which can have permission to restart the service, but your users cron may not. The /dev/null 2>$1 will stop the email notification going to your root email account (something you probably don't check anyway). – Phil Lawlor Dec 18 '14 at 19:24
  • For the crontab I was logged in as root when editing it, also i have the MAILTO= set to the email address I wanted so I get the status of the job. – LinG33k Dec 18 '14 at 19:53
  • So when you "log in as root" are you switching to root or doing sudo? "su root" or "sudo -i"? In any case do you see your restart command in the crontab when you "sudo crontab -e"? – Phil Lawlor Dec 19 '14 at 15:12
  • Also if you tail your syslog do you see an error in it? I tested with "*/5 * * * * /etc/init.d/samba restart >> /dev/null 2>&1" and checked: "tail -f /var/log/syslog" should have: Dec 19 10:15:01 [NAME] CRON[30422]: (root) CMD (/etc/init.d/samba restart )" – Phil Lawlor Dec 19 '14 at 15:19
0

Update: I see this is the syslog for the crontab that is setup to run at the beginning of the day to restart samba and nothing else in the syslog:

Dec 19 00:00:01 storage /USR/SBIN/CRON[25935]: (root) CMD (/etc/init.d/samba restart)

I get this in my email report setup:

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!

This is the cronjob to run tonight:

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

I created one just like the above, but to run every top of the hour to test it.

0

You have to set the right path in your crontab

See the output of

echo $PATH

And put this in your crontab:

PATH=... here the output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.