[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1189
  • Last Modified:

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.
0
ray-solomon
Asked:
ray-solomon
  • 4
  • 2
1 Solution
 
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
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
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
 
ray-solomonAuthor Commented:
Great, I used your solution.

Thanks.
0

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now