FedoraThis forum is for the discussion of the Fedora Project.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I've added 3 shell scripts to my cronjobs. 2 of them run and work fine. The cron log shows the 3rd also runs, but it doesn't do what it's supposed to do. If I run the 3rd script myself, on the command line, it works fine.
The script that isn't working just deletes some old files. But those files are owned by root. So I'm guessing that the scrip isn't running as root from cron. From Googling, it looks like I'm supposed to run crontab -e as root and set the script to run. But that's what I'm doing. Am I missing some other step?
You're probably not missing anything. Personally I'd run the files from /etc/crontab, which is broadly the same as the root crontab, but I'd describe the difference as the system vs the root user, which is basically the same thing technically.
more often it's a case of the script not having a suitable interpreter in the script or such like, what is the script? You might find it simpler to drop the whole thing into /etc/cron.daily or some such location. That's my preferred option, if you need to run it on a common schedule that already exists in /etc/crontab
The script is very simple. It doesn't run any perl or bash logic or anything fancy like that. It just uses some standard executables. Basically, files are backed up every day. But I only want to keep a few days worth of backups. So the script just finds the old ones and deletes them.
I think you all are making this more complicated than it needs to be.
To run a script as a cronjob with root permissions, create and test your script as root.
Once you've verified that the script works without error, run crontab -e in a terminal as root and edit the crontab file to add your script to the crontab (cron table).
See man crontab for more information.
This is exactly what I've done. I've set several other scripts up the same way. This one is not working. I'm not sure what the issue is, perhaps find with exec doesn't work with cron? I've written up a much more complicated shell script that does the same thing as what I had the one liner find command doing. Since the non-find script seems to be working, I guess I'll stick with it.
Normally cron is to be treated as a any user. To include all permissions and to include all environmental settings. Any cron script ought to be available as if any other user ran it if all of the permissions and environment are satisfied.