[ILUG-BOM] Backup Internet Line

Raj Mathur raju at linux-delhi.org
Tue May 5 21:37:04 IST 2009


On Tuesday 05 May 2009, george at annamsoft.com wrote:
> Can you pl. explain me the below line from your while...do loop.
>
> if ifconfig ppp$iface > /dev/null 2>&1

$iface is 0 or 1 or whatever.  ppp$iface is ppp0 or ppp1...

ifconfig ppp0 > /dev/null 2>&1 will try to get the status of interface 
ppp0.  We discard the output of ifconfig since we're not interested in 
it by sending it to /dev/null.

ifconfig exits with 0 (true) or non-zero (false) depending on whether it 
could get that status of the specified interface or not.  We check the 
exit value in the if and perform tasks accordingly.

help if
man ifconfig
man sh (look at the REDIRECTION and Parameter Expansion sections)

Regards,

-- Raju

> > while :
> > do
> >   for iface in 0 1
> >   do
> >     if ifconfig ppp$iface > /dev/null 2>&1
> >     then
> >       /sbin/route delete default
> >       /sbin/route add default dev ppp$iface
> >     fi
> >   done
> > done

-- 
Raj Mathur                raju at kandalaya.org      http://kandalaya.org/
       GPG: 78D4 FC67 367F 40E2 0DD5  0FEF C968 D0EF CC68 D17F
PsyTrance & Chill: http://schizoid.in/   ||   It is the mind that moves


More information about the Linuxers mailing list