Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a test.sh script

#!/bin/sh
php /home/v/file.php
sh /root/x/some.sh

when I execute the file as root from command line it works.

sh /home/v/test.sh 

when I set it to crontab -e (is the root cron), is not working

 * * * * * sh /home/v/test.sh

What do I do wrong? Thanks

share|improve this question
    
up vote 5 down vote accepted

The enviroment for cron to run into is very very limited, try to always use full path for binaries.

#!/bin/sh
/usr/bin/php /home/v/file.php
/bin/sh /root/x/some.sh

This considers that your php binary is in /usr/bin/php, please change that appropiately if it's not the case

Also try to add in top of your cron the MAILTO line in order to get a direct mail with any error that can happen during the execution

MAILTO=youraddress@yourmail.com
* * * * * sh /home/v/test.sh
share|improve this answer

It is probable the php binary isn't in the default cron PATH. You should put the full path to your php binary in your script

/usr/bin/php /home/v/file.php

You should also provide a path for sh

/bin/sh /root/x/some.sh

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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