bash: check for network

Nicholas Leippe nick at
Thu Apr 14 10:06:51 MDT 2005

On Thursday 14 April 2005 09:39 am, Dan Wilson wrote:
> Hey all,
> I've got a cron script that connects to a remote server to accomplish a
> few tasks.  I run this on my laptop and sometimes don't have a network
> connection.  If there is no connection, I just end up getting a bunch of
> emails stuck in the queue and eventually sent to me that say it couldn't
> connect to the server.
> So within my script, I'd like to be able to check if I have a network
> connection prior to starting my tasks.
> I'm sure there is an easy way to do this (without too much awk, sed and
> grepping, etc).  Any ideas?

ping -c 1 <some ip> >/dev/null
if [ $? = 0 ]; then # ok


Nicholas Leippe
Sales Team Automation, LLC
1335 West 1650 North, Suite C
Springville, UT  84663 +1 801.853.4090

More information about the PLUG mailing list