LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 10-20-2008, 03:44 PM   #1
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Rep: Reputation: 15
Any help with this script?


Hi! I'm running this script and it seems to "almost" work. It pings the IP address but when it gets a "1" condition it won't reboot like I want it to. Script:

ping -c 5 123.45.678.910
echo $?
if [ $? -ne 0 ] ; then shutdown -r -t 10 "now"
fi


That's it... I can run "shutdown -r -t 10 "now"" from the root and it works just fine.

Thanks!
 
Old 10-20-2008, 03:59 PM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
In your if condition, you're testing the exit status of the echo command. If you want to test the exit status of the ping command and display it, then assign the exit status to a variable, echo that and then test it.

Code:
ping 
foo=$?
echo $foo
if [ $foo -ne 0];then

Last edited by arizonagroovejet; 10-20-2008 at 03:59 PM. Reason: typos
 
Old 10-20-2008, 04:11 PM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Ahh, your echo command running before the if is setting $? to 0, so the if is always true. Remove the echo and it should work. (edit: I see Arizona beat me to it)


BTW, You could simplify it a little, no need for the if/test on $?

Code:
 
ping -c 5 123.45.678.910 || shutdown -t 10 -r now

Last edited by GazL; 10-20-2008 at 04:13 PM.
 
Old 10-21-2008, 03:25 AM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
This should make apparent one of the problems with cross-posting; you get two fragmented sets of answers. See http://www.linuxquestions.org/questi...script-677882/
And, of course, its against the forum rules.
 
  


Reply



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
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 03:29 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:23 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
Open Source Consulting | Domain Registration