Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
I have a php script which creates a temp directory. Then makes other stuff and finally removes the temp directory.
If I run the script with user root directly in the CLI, everything works fine.
However, the cron task throws an error while trying to delete the temp directory. Crontab is owned by root, so the user launching the script should be the same.
If I run the script with user root directly in the CLI, everything works fine.
In your script, try using the full path to the problem directory, not the relative path. That's the most common reason why a script runs fine when run as root in a terminal but fails when run under cron. Make sure all references in your script to locations are using the full, absolute path.
In your script, try using the full path to the problem directory, not the relative path. That's the most common reason why a script runs fine when run as root in a terminal but fails when run under cron. Make sure all references in your script to locations are using the full, absolute path.
I'll try and post the results. Thanks for the guidance!
Also, your script may be dependent on some environment variables that you use while logged in via command line.
Keep in mind that you .bashrc or any type of .profile is not run when a cron job is run. It basically has no environment.
For example is the location of a library .lib file is required, you'll have to add that environment variable to the cron job. Ditto for anything using a .so file (shared code library).
When I run something in a non-bash, non-sh command (perl, python, etc) - and it's a script/program that I don't want to mess with in its code - I may create a .sh file to call from cron which puts in all the missing environment things I want via "export" commands, and then calls the intended perl/python/etc script.
Yes, you can do all this in the cron command itself, but I really prefer clear/plain simple cron entries (pedantic, I know).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.