Passing Ping command's reply

General discussion about Linux, Linux distribution, using Linux etc.

Passing Ping command's reply

Postby Misam Shah » Fri Jul 17, 2009 3:08 pm

AOA All,
Is it possible that we can pass the values of ping command to a variable of boolean type? I am actually trying to test a link whether it is up or not, for this I am using ping c1 but don't know how to get the value in true or false by this, true when ping is replying ok and false if it replies destination host unreachable.

I am pretty much confused, anyone please help :(.

Thanks
Misam Shah
Lance Naik
 
Posts: 32
Joined: Mon May 04, 2009 4:08 pm
WLM: misamshah@hotmail.com
Yahoo Messenger: misamshah@yahoo.com
Location: Hyderabad

Postby lambda » Fri Jul 17, 2009 3:56 pm

rtfm.

Code: Select all

me@sarwar:~$ ping -qnc1 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.542/1.542/1.542/0.000 ms
me@sarwar:~$ echo $?
0
me@sarwar:~$ ping -qnc1 192.168.1.234
PING 192.168.1.234 (192.168.1.234) 56(84) bytes of data.

--- 192.168.1.234 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

me@sarwar:~$ echo $?
1
me@sarwar:~$
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore


Return to “%s” General

Who is online

Users browsing this forum: No registered users and 3 guests

cron