Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need help. Currently using OpenSUSE distribution and I need to create a bash script, that will ping two IP addreses and only do an action if both are unavailable. Is that possible somehow ?
Yes, see how to do conditional statements, as well as the full manual for ping
Code:
man ping
All programs produce an exit code and can thus be used in a conditional statement. If you want to save that exit code for later, then save the variable $? to another variable immediately after the program is run before doing anything else.
How far can you get with that? Which shell scripting guide or tutorial are you working from?
for i in ip_one ip_two ; do ping -c 1 -w2 $i> /dev/null ; if [ $? -eq 0 ] ; then echo $i appears up; else echo $i ""may"" be down ; fi ; done
Example:
Code:
for i in 185.156.173.235 52.202.3.120 ; do ping -c 1 -w2 $i> /dev/null ; if [ $? -eq 0 ] ; then echo $i is up; else echo $i ""may"" be down ; fi ; done
provides
Code:
185.156.173.235 is up
52.202.3.120 may be down
Read the conditionals link provided by Turbocapatalist, it's used in my example.
I don't trust it as "reliable" and it is firmly stuck in my noggin'.
Just sayin'
script unused since 2014-01-15
When I don't trust ping, I use SNMP:
Code:
snmpget -v 1 -c public <some IP address/host> 1.3.6.1.2.1.1.1.0"
...and replace the version and community as needed too. That OID is the system OID, and that particular node will return the system description. 1.3.6.1.2.1.1.5 will return the system name as set in the SNMP configuration.
I trust that a *BIT* more, because I've seen systems respond to an ICMP ping, but be non-responsive otherwise. This, at least, indicates the system is functioning on SOME level past Layer 3.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.