You are not logged in.

#1 2016-05-30 6:19 pm

Peetee
Member
Registered: 2016-05-29
Posts: 4

Script working, but not from cronjob

Hi all,

When I run a php-script that checks the emailaddress against the API, it works like expected. But when run the same script from a cronjob no noticable action is visible, it just doesn't do anything.

What could be the cause for this?

Last edited by Peetee (2016-05-30 6:32 pm)

Offline

#2 2016-05-30 7:04 pm

Alex Kemp
Moderator
From: Nottingham, England
Registered: 2009-12-02
Posts: 2,420
Website

Re: Script working, but not from cronjob

Hi Peetee, welcome to SFS.

Without an error message it's impossible to say. Unfortunately, my psychic visions are only available every other day.

Put in some error reporting & see what it says.

Offline

#3 2016-05-30 7:24 pm

Peetee
Member
Registered: 2016-05-29
Posts: 4

Re: Script working, but not from cronjob

Ah. that is ashame. I really hoped you would be a psychic. ;-)

The problem is that I don't get any errors. So I hoped that someone could tell me something without them ...

One question though: should I use WGET or just the PHP parser?

Offline

#4 2016-05-30 7:49 pm

zero-tolerance
Member
Registered: 2013-02-25
Posts: 339

Re: Script working, but not from cronjob

How sure are you no error message is generated?
If you're not sure, try altering your cronjob so it will definitely generate an error message (e.g. start it with a command that does so), and find out where the error message gets sent. It may end up in some obscure log file, or get emailed to you, or something. This will also confirm that the cronjob is running at the predicted times.

Offline

#5 2016-06-02 1:29 pm

kpatz
Member
Registered: 2008-10-09
Posts: 1,437

Re: Script working, but not from cronjob

See if the cronjob is running under the same user/group that you are running the script manually, and make sure any environment variables that may be set in your shell session are also being set in your cronjob script (i.e. PATH).  Fully qualifying the paths to executables helps as well, in case PATH isn't set.

Redirect stdout and stderr to a log file (/path/to/your_script >>/home/yourusername/yourscript.log 2>&1), let the cronjob run, then check the log.

Last edited by kpatz (2016-06-02 1:31 pm)


Spam happens when greed meets stupidity.

Offline

#6 2016-06-02 7:19 pm

Peetee
Member
Registered: 2016-05-29
Posts: 4

Re: Script working, but not from cronjob

Thanks, kpatz. I followed your good advice and found out that way that I made a stupid mistake: I limited the script to only work from my ip-address. And of course: the server where I run the cronjob has another one ... :-((

Thanks to all of you for your help!! :-)

Offline

#7 2016-06-03 9:08 am

pedigree
uıɐbɐ ʎɐqǝ ɯoɹɟ pɹɐoqʎǝʞ ɐ buıʎnq ɹǝʌǝu ɯ,ı
From: New Zealand
Registered: 2008-04-16
Posts: 7,054

Re: Script working, but not from cronjob

if you're using PHP and using curl then curl will need to be enabled for the cli version, usually with a symlink in /etc/php5/cli/conf

Offline

#8 2016-06-03 10:51 am

Peetee
Member
Registered: 2016-05-29
Posts: 4

Re: Script working, but not from cronjob

The problem is solved now. I changed the script and itruns like a charm now. Thanks.

Offline

Board footer

Powered by FluxBB

Close
Close