LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to check ICMP code through shell script? (https://www.linuxquestions.org/questions/linux-networking-3/how-to-check-icmp-code-through-shell-script-344618/)

Thakowbbery 07-19-2005 08:06 AM

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?

ilnli 07-19-2005 09:41 AM

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`

keefaz 07-19-2005 09:52 AM

You could also short it a little as :

Code:

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



All times are GMT -5. The time now is 09:40 AM.