LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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

Reply
 
Search this Thread
Old 11-17-2008, 11:31 AM   #1
RavenLX
Member
 
Registered: Oct 2004
Posts: 95

Rep: Reputation: 15
Question 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?
 
Old 11-17-2008, 11:35 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
You probably need to specify the full path to the commands issued and make sure it's getting run as root user.
 
Old 11-17-2008, 11:43 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Rebooting a server seems a bit drastic; can't you just restart the relevant services, if they're the root of the problem?
 
Old 11-17-2008, 12:04 PM   #4
RavenLX
Member
 
Registered: Oct 2004
Posts: 95

Original Poster
Rep: Reputation: 15
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.
 
Old 11-17-2008, 01:00 PM   #5
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by FuzzieDice View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script system() only execute one command knockout_artist Programming 4 11-11-2008 11:57 AM
verify system username & password in a perl script exodist Programming 3 08-15-2006 05:42 AM
Getting PID from a system command in Linux perl script sumbabs Linux - General 1 03-03-2005 11:38 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
PERL script that can browse the file system... vous Programming 1 02-09-2004 02:02 PM


All times are GMT -5. The time now is 03:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration