LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 07-19-2005, 08:06 AM   #1
Thakowbbery
Member
 
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, 09:41 AM   #2
ilnli
Member
 
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)

Code:
#!/bin/bash

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)
exit
endif
done;
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.

$variable=`command`
 
Old 07-19-2005, 09:52 AM   #3
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,603

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

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


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 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 04:55 PM
new shell window by script or code r2d2 Programming 2 12-14-2005 01:59 PM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM
c code vs shell script again? khucinx Programming 1 05-12-2004 09:44 PM
c code vs shell script? khucinx Programming 1 05-12-2004 06:06 PM


All times are GMT -5. The time now is 11:54 PM.

Main Menu
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