Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 07-19-2005, 09:06 AM   #1
Registered: Mar 2005
Posts: 135

Rep: Reputation: 17
Question How to check ICMP code through shell script?

Hello to everyone.

I need to run a script so that I can check if a machine is still running. If somehow it goes offline then the machine which is making the check take its place, by changing its IP.
Can someone help me out with that?
Old 07-19-2005, 10:41 AM   #2
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Rep: Reputation: 32
you have to do some work with shell scripting i don't know the exact syntax at the moment so i am giving a hint at this time.(just like a psudo code)


while true; do
$var1 = `ping  your server`
if var1 eq "time out" then
 remove previous ip (using ifconfig command)
 add new ip (using ifconfig command)
one thing i want to make clear here is that in shell code if you want the output of command to be saved in a variable then you use ` operator which is present just before 1 on keyboard.

Old 07-19-2005, 10:52 AM   #3
Senior Member
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 137Reputation: 137
You could also short it a little as :

if ! ping -c 1 <host IP>; then
   # host is down


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can we hide the code of a Shell Script? kushalkoolwal Programming 35 03-30-2011 05:55 PM
new shell window by script or code r2d2 Programming 2 12-14-2005 02:59 PM
return value from shell script to c code? khucinx Programming 1 05-13-2004 04:43 PM
c code vs shell script again? khucinx Programming 1 05-12-2004 10:44 PM
c code vs shell script? khucinx Programming 1 05-12-2004 07:06 PM

All times are GMT -5. The time now is 12:49 AM.

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