cd some_dir && php some_crone.php || echo "$? $_" | xargs ./some_handler.php
So when I run this code from console I got a correct value for $? and for $_
$? – exit status
$_ – Gives the last argument to the previous command. At the shell startup, it gives the absolute filename of the shell script being executed.
But when I put this code to cronjob :
crontab -e
*/1 * * * * cd some_dir && php some_crone.php || echo "$? $_" | xargs ./some_handler.php
I got an empty $_.
Please help. I can not understand what a problem?
Change crontab’s default shell from /bin/sh to /bin/bash by adding the following line to your crontab.