omegaweaponZ has asked for the wisdom of the Perl Monks concerning the following question:

I have a quick cronjob question for everyone. I am running a script where I am running a JBOSS call, as in: system("service jboss blah blah blah"); Now this works manually but fails in the cronjob. The system command itself works as if I put anything else, such as echo to a text file, it outputs fine. The error I get from this outputting in the cronjob is as follows: Can't exec "service": No such file or directory So the question is, why is the command "service" not working in cronjob but works manually. Thanks

UPDATE - THIS IS RESOLVED, NEED to add full path is before service, as in /pathtoservice/service. Thanks for the help!

Replies are listed 'Best First'.
Re: Calling System Service command fails in cronjob
by reisinge (Hermit) on Aug 13, 2012 at 19:32 UTC
    Specify the full path to the service command, e.g.:
    system("/usr/sbin/service jboss blah blah blah");
    You can find out the full path to service command like this:
    # which service
    If this works your problem is most probably the PATH environment variable. From section 5 of Debian crontab manpage: "Note in particular that if you want a PATH other than "/usr/bin:/bin", you will need to set it in the crontab file."

    Update: You should also search PM for something like "crontab path" to get further advice.

    Have a nice day, j

Re: Calling System Service command fails in cronjob
by blue_cowdawg (Monsignor) on Aug 13, 2012 at 19:42 UTC
        The error I get from this outputting in the cronjob is as follows: Can't exec "service": No such file or directory So the question is, why is the command "service" not working in cronjob but works manually.

    Never make assumptions. I noticed right off as someone else did that you did not specify the path to your command. The PATH variable you see from the command line is likely to be different than what a cronjob is going to see. There are a couple of ways you can cure this:

    1. You could specify the full path name to the command you are trying to invoke from system
    2. Add a fully populated PATH to your crontab. Warning be careful of what directories you add to your PATH from within your crontab. This could lead to a security hole so be sure of what you are doing.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
      Good call, that was the issue. Need a full path always to crontab's. Thanks! This issue is now resolved
Re: Calling System Service command fails in cronjob
by kcott (Archbishop) on Aug 13, 2012 at 19:59 UTC

    You've received good advice on this already.

    You should also be aware that $PATH is not the only environment variable that may have a different setting under cron to what you normally have with whatever shell you use; in fact, $SHELL may not even be the same. Section 5 of the crontab manpage should provide details for your system:

    man 5 crontab

    -- Ken

Re: Calling System Service command fails in cronjob
by Anonymous Monk on Aug 13, 2012 at 21:33 UTC
    Usually it is best to specify the =exact path= to a script which sets-up everything that the request needs ... environment variable settings especially. Cron only has to execute the script; the script does everything(!0 else. You also must of course be mindful that cron jobs must execute under the proper user credentials...