0

I created a small bash script that takes a file using wget and then processes it using a php. The code goes like this:

wget -U mozilla -P /home/logfetcher/ http://fakesite.com/log.`date -d 'yesterday' +%Y-%m-%d`.csv
wait    
/usr/bin/php csv-editor.php /home/logfetcher/log.`date -d 'yesterday' +%Y-%m-%d`.csv /home/logfetcher/sorted/log.`date -d 'yesterday' +%Y-%m-%d`.csv 3 9 7 0 2 1 5 11 12 13 && rm /home/logfetcher/*.csv

I tested it and it works without any problems, though when I added it to cron like this:

0 6 * * * /home/logfetcher/fetchlogs.sh

It downloads the file but the php seems to don't work at all (nor the rm, which I guess indicates an error trying to run the php file). I've been trying to think about why this could be failing and tried a few things, but I don't seem to find a proper answer to fix it. Any help would be appreciated!

1

What is cron log saying? Or syslog? If there is error with first part of command then second command (after &&) won't be executed. is script csv-editor.php in your PATH? If it isn't than you should run it with absolute path /x/y/my.script.

I'm pretty sure that script isn't in your path, so "/usr/bin/php /x/y/script.php ...." should resolve problem.

But first read the logs...

| improve this answer | |
  • I cannot believe I didn't think about that! Adding the full path to the script indeed fixed it. Thanks a lot Neven – Daniel Sanchez Aug 7 '15 at 9:14
  • 1
    Yeah the simplest thing are always hardest to spot. If this helped you, then please mark my post as an answer. Cheers – Neven Aug 7 '15 at 9:17
1

There are 2 solutions. Either you add #! /bin/bash as a first line in your script or you start your crontab file with the following 2 lines:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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