Link to home
Start Free TrialLog in
Avatar of databoks
databoksFlag for Denmark

asked on

Check Interface state(up/down) and grep 'recieved' in ping

Hi experts.

How can I accomplish the following:


if(eth0 recives icmp reply && interface eth1 is down)
ifconfig eth1 up
else
ifconfig eth1 down

I am using CentOS 5.6
ASKER CERTIFIED SOLUTION
Avatar of Dilip Patidar
Dilip Patidar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#!/bin/bash
ping -c 2 'xxx.xxx.xxx.xxx' > /dev/null
if [ $? -eq 0 ]; then
echo "Alive";
else
echo "Dead";
fi


You can put forloop of ips.


IPS='1.1.1.1 2.2.2.2 3.3.3.3'
for ip in IPS;do
{
ping -c 2 '$ip' > /dev/null
if [ $? -eq 0 ]; then
echo "Alive";
else
echo "Dead";
fi
}
done