Cron to reboot

I wrote a simple bash script to reboot the server and used a cron job to initiate the reboot every morning, but I get permission denied error messages in my emails showing me it failed.

The script uses the shutdown -r command.

I think its because I have SElinux enabled.

What selinux command can I use to make an exception for this to work?

I still want SElinux enabled.

I know what your thinking...linux does not need to be rebooted everyday, but there is a valid reason why, but I don't want to go into that.

This is on a centos 5.4 64-bit server.

Thanks.
LVL 10
ray-solomonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jack_borshchCommented:
Hello

1) have you specified full path to your shell file in the cron (something like reboot.sh will not work)
2) are you running this cron from root?

Regards
0
ray-solomonAuthor Commented:
Here is crontab -e

### Reboot the server every day at 4:00 am
00 4 * * * /root/reboot_server.sh


Here is reboot_server.sh

#!/bin/bash
/sbin/shutdown -r now



Yes, its run from root.

Open in new window

0
TintinCommented:
What's the exact error message you get?
0
INTRODUCING: WatchGuard's New MFA Solution

WatchGuard is proud to announce the launch of AuthPoint, a powerful, yet simple, Cloud-based MFA service designed to eliminate the vulnerabilities that put your data, systems, and users at risk.

ray-solomonAuthor Commented:
/bin/sh: /root/reboot_server.sh: Permission denied
0
ray-solomonAuthor Commented:
I just thought of something.

Its probably because I never made it executable.

chmod +x /root/reboot_server.sh

right?
0
TintinCommented:
Correct.  It needs to be executable.  That's definitely not an SELinux error.

Why not just change your cronjob to

00 4 * * * /sbin/shutdown -r now
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ray-solomonAuthor Commented:
Great, I used your solution.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.