2

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

Elzo Valugi
  • 387
  • 2
  • 4
  • 15
  • possible duplicate of [crontab to run bash script (ssh command in it) not working](http://serverfault.com/questions/186448/crontab-to-run-bash-script-ssh-command-in-it-not-working) – Dennis Williamson Feb 02 '11 at 16:02

2 Answers2

6

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
user9517
  • 115,471
  • 20
  • 215
  • 297
lynxman
  • 9,397
  • 3
  • 25
  • 28
2

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

user9517
  • 115,471
  • 20
  • 215
  • 297