How-to auto-start programmes when I connect to Internet?

Hal Burgiss hal at burgiss.net
Sat Feb 14 12:55:56 UTC 2004


On Fri, Feb 13, 2004 at 02:01:04PM +0000, Coume - Lubox.com wrote:
> > 
> > Sure, write a script that checks for connection, and restarts whatever
> > you want it to.
> 
> Could you explain a bit more? Because I do not know how to do what
> you told me... :(

This is the guts of a script I have called "is_up". I call this from
other scripts to test my connection. This script just tests local
networking, and not necessarily connectivity with my ISP (that is
another script, more complex to ping local gateway and nameserver).

#!/bin/bash

IFACE=eth0

 if ! ifconfig | grep $IFACE >/dev/null 2>&1 ||\
    ! ifconfig $IFACE | grep UP >/dev/null 2>&1; then
  #if the interface is down, then the connection surely is too!
  echo "Interface is down"
  exit 1
 fi

 echo "Interface is rockin"
 exit 0

# end of script

Another script might look like .... (untested!!!)

#!/bin/sh

services="licq named postfix blah"

if ! is_up >/dev/null; then
  # whatever means of restarting networking
  restart_interface
fi

if is_up >/dev/null; then

  for i in $services; do 
    service $i restart
  done
  exit 0

else
  echo "You have failed me miserably!"
  exit 1
fi

# end

########################

The easiest thing is to run this stuff from cron every so often. You could
also run it within a script  ...

#!/bin/sh

 while sleep 30; do
   # this is second script above
   test_connect.sh
 done

# will run forever 
# end
# that is all

-- 
Hal Burgiss
 





More information about the users mailing list