Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Hi,
I've got a cron setup under user root. The cron writes to a file and does a few other things. The thing is no matter what chmod I set the directory (which happens to be /root/test/) the script is contained in, and no matter how I chmod the script itself and the file it reads and writes, I just can't get the script running under root cron to write to the file. When I run the script myself manually it works fine - it writes to the file and there is no problem. But when the cron executes the script it won't write to the file.
I edit the cron file logged in as root user and using command "crontab -e"
As far as I know I am doing everything right - does anyone know why when executed by the cron the script fails to write to the file?
have you checked the path directory. as when you are logged in as root the path is set. but when cron runs it does not run the /root/.bashrc and profile. try modifing the script to say /root/test/whatever. instead of whatever.
thanxs
wolfe
ok so you have this script that will not run from cron. check your crontab
make sure the path is right and that the file in /etc/crond.daily/whatever is right to run the script. if all of these are correct then it should run just fine. but when cron runs the program as root it uses that path in the crontab to run it. also you could just put the script in cron.daily or monthy or whatever. cron just runs whatever is in that dir.
wolfe
thanks again for offering your thoughts. The cron does execute the script, I get emails telling me it worked. It just doesn't seem to be running as root user. Its like another user is running it and because of that when the script runs it can't open any files or write any files.
The cron is not the "daily", "weekly" ones its the ones in /var/spool/cron . This is the directory where all users on the server have their own crons running, one of the users is "root", when I am logged in as root user (using su command) I type "crontab -e" and edit the root cron in this directory. I need to run the cron every minute, its a process monitoring script that contantly checks for runaway processes and also checks services are running.
Maybe crons in the /var/spool/cron directory just can't run root crons? If nott how could I setup a root cron to run every minute by another method?
Ok,
sorry I found the cause. I have the main config file being accessed as "./config.file". No wonder everything else is failing because this config file is not being read at the very start of the program. Sorry I should have checked this more, thanks for your help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.