The Above works on Ubuntu 12.04 The /sys may not exist on some other distros. I feel ping is not the best thing to use here because it aims to test a connection to a particular host NOT test if there is a connection to a network of any sort. See man bash and search for "Expressions may be combined" for more details. Note for those new to bash: The final 'if' statement tests if NOT online and exits if this is the case. If ! then echo "Not Online" > /dev/stderr exit fi #!/usr/bin/bashįor interface in $(ls /sys/class/net/ | grep -v lo) The script below prevents me from receiving popup messages every five minutes whenever my laptop is not connected to the network. If it's NOT accessible a popup window alerts me to a problem. I use the below in another script that I have for periodically testing if my website is accessible. Here's my script to test for a network connection other than the loop back. Looking in /sys/class/net should be one way Super Thanks to user somedrew for their post here: on 02:09:48
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |