LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-22-2005, 04:41 AM   #1
dtra
Member
 
Registered: Nov 2004
Distribution: fc4
Posts: 104

Rep: Reputation: 15
php script will not run correctly as cron, fine from cli


hi all

i am about to die here

i've got this php script that reads an email inbox and processes email attachments (jpegs/videos)

but it just will not work properly when i run it as a cron
there are two parts to it

it checks the email for attachments, and includes a separate script to process images (works fine)
the other part checks for videos (does not work as cron, works when run from cli)

what am i doing wrong

i run it from the cli as the same user that runs it as cron, i don't know why it won't work
we used to have a similar script that ran fine, but that one won't work cos it needed to be sent emails manually (this script is exactly the same but it checks a different email address)

anyone have any ideas, i'm dying here (i'm meant to go on holiday tomorrow, but i have to get this done)

thanks
dave
 
Old 12-22-2005, 05:59 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
You say that you're using the same user on the cli (command line interface) as with cron.
However, you must know that all cron jobs have a separate environment.
The user's profile and other environment settings ($PATH, etc) thus are not used when running it with
cron.

To fix this, there are basically 2 ways:
-Copy the environment variables that are set in the .profile, .bashrc, etc of the user and paste that at the
top of the file that contains the crontab settings.
Note that you don't need to export the variables. Just specify them as: VAR=<some_value>;
All cron jobs (specified in the same file) will then be able to use those environment settings.
-Include the entire .profile and alike files in your script by adding "source $HOME/.profile" (note: cron
sets $HOME, $SHELL and $LOGNAME appropriately, so they can still be used). See "man crontab".
The drawback of this second approach is that you need to add "source <some_files>" to all your scripts.

Note also that the MAILTO environment variable is also set up by cron and contains the mail adress where the standard output/error messages of cron jobs should be sent to. Typically, mails are sent to the user who asked
cron to run the jobs on his/her behalf. Using:
MAILTO=
will disable the mails.
MAILTO=root
will send the mails to root instead of the user, etc.

Google around for explanations on "cron", "Vixie cron" (if your cron was written by Paul Vixie - see man Cron).
 
Old 12-22-2005, 07:21 AM   #3
dtra
Member
 
Registered: Nov 2004
Distribution: fc4
Posts: 104

Original Poster
Rep: Reputation: 15
thanks for the tips

but i got it working i think, i don't think env variables were an issue, as it's just a php script that runs (it could almost be run from the web)
i think it was conflicting with some other cron or something, cos when i changed the timing, it worked

dave
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron issue, php script runs fine in browser and cli dtra Linux - Software 1 07-15-2005 05:45 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 06:34 PM
script runs fine from a command line, but doesn't work from cron? kleptophobiac Linux - Software 5 05-03-2004 04:14 PM
script not running correctly off cron wedgeworth Linux - Software 3 10-14-2003 08:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration