Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-17-2008, 10:31 AM
|
#1
|
|
Member
Registered: Oct 2004
Posts: 83
Rep:
|
How do I reboot system from perl script?
I have a perl script that runs from a root cron job and tests a few things and if those tests fail, then to reboot the whole system (Ubuntu 8.04 LTS server). Thing is, it's not rebooting. It does nothing.
I've tried each of these:
exec("reboot -f");
exec("shutdown -r now");
system("reboot -f");
system("shudown -r now");
None of these will reboot the system. Yet, in an automated install script the 2nd method WORKED. (I set it up though so you had to press a key to reboot). This time, I *don't* want any keypresses. It should be automatic as I need this to work as a self-healing option.
Anyone know how to do this?
|
|
|
|
11-17-2008, 10:35 AM
|
#2
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
You probably need to specify the full path to the commands issued and make sure it's getting run as root user.
|
|
|
|
11-17-2008, 10:43 AM
|
#3
|
|
Senior Member
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,843
Rep: 
|
Rebooting a server seems a bit drastic; can't you just restart the relevant services, if they're the root of the problem?
|
|
|
|
11-17-2008, 11:04 AM
|
#4
|
|
Member
Registered: Oct 2004
Posts: 83
Original Poster
Rep:
|
pwc101 - The script does attempt to restart servers, but in the event that servers still can't be restarted, then a reboot will commence.
BTW, I figured it out. My path was right, it was that it needed the right permissions. Doing this worked from cron job:
exec("sudo shutdown -r now");
Whenever you want to use system-type commands, even within the root cron job (ie. crontab -e), you have to specify 'sudo' for some odd reason.
|
|
|
|
11-17-2008, 12:00 PM
|
#5
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Quote:
Originally Posted by FuzzieDice
pwc101 - The script does attempt to restart servers, but in the event that servers still can't be restarted, then a reboot will commence.
BTW, I figured it out. My path was right, it was that it needed the right permissions. Doing this worked from cron job:
exec("sudo shutdown -r now");
Whenever you want to use system-type commands, even within the root cron job (ie. crontab -e), you have to specify 'sudo' for some odd reason.
|
Actually your path as root might have been right but cron doesn't see that path usually. You can probably remove sudo from your script and either put PATH=/paths/here;/path/here within you're crontab so it knows where to look for such commands.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:46 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|