Forum Moderators: bakedjake

Message Too Old, No Replies

running shell script through crontab

         

askipper

11:53 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Very new to this to please bear with me.
I have a simple requirement... (I hope)

I want to run a .php file called fetch.php that basically gets emails from a pop3 account and loads them into my helpdesk database.

When I log onto my managed server (linux) through SSH and navigate to the directory with the php file and type this:
php email_fetch.php
all works fine.

So, I set up a .sh file and dumped it with full permissions in my home directory on my webserver.
The .sh file is called helpdesk.sh and has this in it:
cd PN/helpdesk
php email_fetch.php

In my crontab I have this:
32 0-23/1 * * * $HOME/helpdesk.sh

The idea being that on the 32nd minute of every hour run the script.

However, nothing is happening - any ideas why? I'm sure it's obviousl to all you gurus out there but as this is my 1st attempt at crontab or shellscript...

Thanks in anticipation

incrediBILL

12:03 am on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you specify the explicit path to the script?

Like:
/etc/cron.weekly/myscript

askipper

12:23 am on Feb 16, 2005 (gmt 0)

10+ Year Member



Hi, in the .sh file (which is stored in the $HOME directory) the PN/helpdesk is the path it needs to take from there.

However, if I do a pwd on the $HOME directory it comes up with this:
/kunden/homepages/42/d98345334/htdocs

don't know what all that is but it is a managed server after all!

The path specified in the crontab to the ,sh file is $HOME/helpdesk.sh so I think that's OK.

Do you think the shell script needs changing to include all of the above in the patch to the php script?

askipper

12:33 am on Feb 16, 2005 (gmt 0)

10+ Year Member



I have not changed the helpdesk.sh script to be this:
php /kunden/hom (etc etc)/PN/helpdesk/email_fetch.php

still no joy

If I run the above command it works though so that path is absolute and correct.

Am I missing something in the syntax? Should there be a ; or somrthing at the end of this line?

What about the syntax on the crontab line? SHould it end with a semi-colon or not at all?

Thanks again

gettopreacherman

5:14 pm on Feb 17, 2005 (gmt 0)

10+ Year Member



I have noticed the same with a simple script I am attempting to run. If I run the script "sh *.sh" it runs fine, but calling the file in the *.cron file it doesn't launch...which is interesting...

5,10,15 * * * * /root/*.sh

Just an example...I want it to run every 5 minutes, too lazy to write out all of the minutes, but it won't launch the script file...i even tried the /root/sh *.sh and nothing still...is there a separate synatx for launching shell scripts with crontabs?

MamaDawg

11:36 pm on Feb 17, 2005 (gmt 0)

10+ Year Member



askipper - a couple ideas:

- Good practice to start your shell scripts by specifying the command interpreter on the first line - i.e. #!/bin/sh

- Cron runs with a stripped down environment and path, it may not be able to locate the php command - might need the full path to it i.e. /usr/local/bin/php

- Trapping output and error output to a file may help you see what it doesn't like:

32 0-23/1 * * * $HOME/helpdesk.sh > $HOME/tempfile.txt 2>&1

askipper

12:03 am on Feb 18, 2005 (gmt 0)

10+ Year Member



Thanks - I'll try that - as I still can't get it to work. I'm using www.webcronjobs.com or something like that right now to run the php script.

askipper

12:07 am on Feb 18, 2005 (gmt 0)

10+ Year Member



Hi, tried that and it didn't even leave a tempfile.txt at all. Sounds like the crontab thing is not working at all?

MamaDawg

2:06 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



more likely there's no output (error or otherwise) being generated. You can prove/disprove that by putting an echo (i.e. "echo foo" without the quotes) in the top of your script.

Are there any paths it may not be resolving in email_fetch.php? When a script that runs from the cmd line doesn't run from cron 99% of the time it's an environment and/or path problem.