Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 25th August 2008, 06:58
i.linus i.linus is offline
Junior Member
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Please explain me this shell script.

Guys,

I am new to shell script, and want to learn more about it. i have got one script to report on status of ADSL connection. i can understand half of it (or less then half). can you guys please help me out in this.

Here is the script,
-------------------------------------------------------------------------------------
CONFIG="$1"
if [ -z "$CONFIG" ] ; then
get_device
[ -z "$CONFIG" ] && CONFIG=/etc/ppp/pppoe.conf
fi
if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
echo "$0: Cannot read configuration file '$CONFIG'" >& 2
exit 1
fi
. $CONFIG
PPPOE_PIDFILE="$PIDFILE.pppoe"
PPPD_PIDFILE="$PIDFILE.pppd"
if [ "$DEMAND" != "no" ] ; then
echo "Note: You have enabled demand-connection; adsl-status may be inaccurate."
fi
# If no PPPOE_PIDFILE, connection is down, unless we're using the Linux plugin
if [ "$LINUX_PLUGIN" = "" ] ; then
if [ ! -r "$PPPOE_PIDFILE" ] ; then
echo "adsl-status: Link is down (can't read pppoe PID file $PPPOE_PIDFILE)"
exit 1
fi
fi
# If no PPPD_PIDFILE, something fishy!
if [ ! -r "$PPPD_PIDFILE" ] ; then
echo "adsl-status: Link is down (can't read pppd PID file $PPPD_PIDFILE)"
exit 1
fi
PPPD_PID=`cat "$PPPD_PIDFILE"`
# Sigh. Some versions of pppd put PID files in /var/run; others put them
# in /etc/ppp. Since it's too messy to figure out what pppd does, we
# try both locations.
for i in /etc/ppp/ppp*.pid /var/run/ppp*.pid ; do
if [ -r $i ] ; then
PID=`cat $i`
if [ "$PID" = "$PPPD_PID" ] ; then
IF=`basename $i .pid`
netstat -rn | grep " ${IF}\$" > /dev/null
# /sbin/ifconfig $IF | grep "UP.*POINTOPOINT" > /dev/null
if [ "$?" != "0" ] ; then
echo "adsl-status: Link is attached to $IF, but $IF is down"
exit 1
fi
echo "adsl-status: Link is up and running on interface $IF"
/sbin/ifconfig $IF
exit 0
fi
fi
done
echo "adsl-status: Link is down -- could not find interface corresponding to"
echo "pppd pid $PPPD_PID"
exit 1
-------------------------------------------------------------------------------------

If possible then please explain each line of the script. that what it does.

Any reply would be highly appreciated.
Reply With Quote
Sponsored Links
  #2  
Old 13th September 2008, 03:31
d2e2 d2e2 is offline
Junior Member
 
Join Date: Jun 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default explain shell script

You say you understand some of it. It may be helpful if you began trying to explain the portions you already know. You might then get some help from those of us who are like you, that is from those who know a little and would like to learn it with you.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54
Phone Shell Script ? anything Programming/Scripts 4 6th February 2008 22:33
Shell Script backup a file HELP anything Programming/Scripts 4 5th February 2008 18:09
Need help getting started simple simple shell script dhonnoll78 Programming/Scripts 1 18th December 2007 12:05
need urgent help for writing shell script dips Programming/Scripts 8 3rd September 2006 19:40


All times are GMT +2. The time now is 00:48.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.