Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
    
possible duplicate of crontab to run bash script (ssh command in it) not working –  Dennis Williamson Feb 2 '11 at 16:02
add comment

2 Answers 2

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
add comment

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
add comment

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.