I had programmed a cronjob to restart a service with an apparent memory leak weekly and got an email saying that the killproc command wasn't found.

That's in /sbin/killproc and I don't want to modify the service script, even though I'd prefer it to use absolute paths so I'm opting to weasel my fix by way of cron.

So, I don't want to set the PATH at the top of the crontab file as per the man page apparently says (according to other posts I've seen on the internet, not my man page). How can I structure my crontab line to set one path variable (and not squash root's PATH altogether) just for this script?


This is what I want to do

0 0 * * 0 /etc/init.d/tic_minus restart

this is what I want to avoid

To: Stupid

From: All your customers

Stopping tic_minus: /etc/init.d/tic_minus: line 43: killproc: command not found

Starting tic_minus:


Use a sub-shell to limit scope:

0 0 * * 0 (export PATH=$PATH:/sbin; /etc/init.d/tic_minus restart)
  • 2
    or, more simply: ... PATH=$PATH:/sbin /etc/init.d/tic_minus restart – Jeff Schaller Jan 18 '16 at 14:22
  • 1
    @Jeff I think that might be better since I just got line 48: sleep: command not found by trying this... – Peter Turner Jan 18 '16 at 14:23
  • Just updated mine to append to the existing PATH. – Paul Calabro Jan 18 '16 at 14:26
  • 2
    cron already starts a subshell for your command, so there's not a real need to start a second one; try and see! – Jeff Schaller Jan 18 '16 at 14:27
  • @JeffSchaller Good point! – Paul Calabro Jan 18 '16 at 14:30

Never trust cron env -version => source env setup before command.

0 0 * * 0   (. /usr/xx/myenv ; /some/cmd ) >> /usr/xx/mylog.log 2>&1

myenv include all setup what you need. PATH etc. Use export for variables.

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.