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.
Hi - I'm trying to stop / start Apache using a bash script with CRON. The script needs to run as root, and works when I run it from a terminal while signed in as root.
When CRON runs it apache doesn't restart. I see no messsages in syslog, and cron log shows that the script has run.
service httpd stop >> /etc/httpd/logs/cronroot.txt
service httpd start >> /etc/httpd/logs/cronroot.txt
exit
crontab -u root -e & /var/spool/cron/root has :
09 16 * * * /usr/local/sbin/skdailyA06
Cron log :
Jun 16 16:09:01 hostname crond[17834]: (root) CMD (/usr/local/sbin/skdailyA06)
/etc/httpd/logs/cronroot.txt contains just the line : "--- CronRoot test", and Apache is running with the same task number as before cron ran the script.
I'm using RHEL5.5, and ( as you can probably see ) this is my first 'serious' attempt at cron.
I will bet cron isn't finding the service command. Cron itself runs under a very limited environment. I would recommend for that service command that you make the path explicit: /sbin/service (or whatever the output of `which service` says). Also, I recommend you pause between stop and start.
Another way to do it would be to call the rc script directly (This is pretty much what the service command does):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.