php script will not run correctly as cron, fine from cli
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
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).
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.