0
votes

I want to run PHPUnit on prod server every hour and write result to file. Here's the crontab line:

0 * * * * cd /path/to/project && /usr/local/bin/phpunit --exclude-group acceptance > phpunit.result

When I run that command manually phpunit.result contains expected result, but when using crontab there's only the PHPUnit header in phpunit.result:

PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /path/to/project/phpunit.xml

How can I achieve correct output PHPUnit result to file using crontab?

2
Looks like the process hangs. Can you verify this using ps ax | grep php ?hek2mgl
I think it stops right after start. When I run phpunit manually it take 3-4 minutes to complete all tests and I can see phpunit process. In case of crontab job I can't see that process at the right time.Limon Monte
What do you have in the cron log? If it is empty, you can try strace -f the cron process to see what happens when phpunit is started.VolenD
@user3584460 in cron log (grep CRON /var/log/syslog) there's expected output. strace -f cron isn't very helpful, here's the outputLimon Monte
You are trying to start a new cron process and that would not work, as cron is already running. Try to attach to the existing process - strace -fp cron_process_id (I think I did not explain well in my previous comment and thought that -p option is implied).VolenD

2 Answers

2
votes

You can just use in with one command using full paths. Something like:

php /usr/local/bin/phpunit -c /path/to/project/phpunit.xml > /tmp/phpunit.log 2>&1

It will redirect the std error to the file, too. Then you will see what is actually happening when you run those tests.

-1
votes

Use like this commends in Linux system...

  1. sudo crontab -e =>(create cron tab)

    -> learn command = */2 * * * * wget (i am created crontab for every 2 mins..)

    -> create command for crontab = */2 * * * * wget -q http://localhost/trigger_yoururl

    -> ^o run that..

    -> ^x exit that..

  2. sudo crontab -l =>(list view for cron tab)

  3. sudo crontab -r =>(remove cron tab)