Passing option to bash script help needed

Passing option to bash script help needed

Post by Grey Clo » Sat, 18 Oct 1997 04:00:00



I need to be able to pass options to a script. A simple on/off will
be nice, the script will be use in a crontab to toggle connection to
the net.

Bash doesn't seem to accept it. I tried coping a script and still no go.

Cann someone help?

--
Grey Cloak

         ---------------------------------------------
  .###########.   Change spamtrap to grycloak, to email me.
 ##'___   ___`##   Wizard.FAQ v2.0 send blank Email to:

 ### ) | | ( ###    For other documents served

   #  ~!!!~  #    

http://www.geocities.com/Area51/7614
http://w3.one.net/~grycloak/dreams/dream.htm

 
 
 

Passing option to bash script help needed

Post by Grey Clo » Sun, 19 Oct 1997 04:00:00


On 17 Oct 1997 02:05:02 GMT,
Grey Cloak cause to appear:

Quote:>I need to be able to pass options to a script. A simple on/off will
>be nice, the script will be use in a crontab to toggle connection to
>the net.

>Bash doesn't seem to accept it. I tried coping a script and still no go.

>Cann someone help?

Ok, thanks to an email help, I solve the problem. Before I tell you what
that problem was, please put down any drinks. Drink can hurt the keyboard
on this solution.

As I was trying something new. I decided to test it before changing the
script I was working on. Naturally, to make sure that it worked as
subscriped. (As I expected)

Everything was right in the test script. But it wasn't working. Till
one person send me a clue.... Change the name of the script. Yepp,
I was calling my test script test.

Well, It working now. Thank's. So as a thank you, I going to post the
script. It is used via crontab or command line. It for those who
use pppd with chat.

------------------------cut here--------------------------
#!/bin/sh
#--------------------------
# ppp on/off script
#--------------------------
#
# -modified,
#       9-6-97, discovered logger, echo replaced with logger
#               email is sent on failed log on
#
#     10-10-97, Added handling of Security Log
#               Log is appeneded to new directory
#               Log is mailed to logchecker (me)
#
#     10-17-98, Added command line handling
#
#--- Initailize Variables for run time.
DEVICE=ppp0

#-Determine runstate via pid file
#

case $1 in
#---------------------Kill PPP
off)
      if [ -r /var/run/$DEVICE.pid ]; then
         kill -INT `cat /var/run/$DEVICE.pid`
         logger -i "ppp off option  selected"
         if [ ! "$?" = "0" ]; then          
            rm -f /var/run/$DEVICE.pid
            logger -i "ppp0 found to be stale, removing"
         fi
      fi
      exit 0 ;;
#---------------------Start PPP and handle mail
on)

   if [ -r /var/run/$DEVICE.pid ]; then
        logger -i "PPP Found on line exiting"
        exit 0
   else
        logger -i "pppd found off-line: REinitiating pppd connection"
        /usr/sbin/pppd

        #--- Sleep 50 seconds to insure connection to ISP.
        sleep 50

        #--- Check for successful run
        if [ -r /var/run/$DEVICE.pid ]; then

                #--- Retrieve inbound email, Send outbound email

                logger -i "calling sendmail -q to send any queued mail."
                sendmail -q            

                #--- Process Security Log send to grycloak

        else
                #--- Get the reason for the fail
                tail /var/log/messages
                logger -i "pppd failed, messages tailed to /root"

                #--- this will cuase crond to send email to owner
                echo ppp-on failed at $(date +"%D at %T")
                echo check /root/ppp-on, Most likly modem failure.
                exit 1

        fi
     fi
     exit 0
        ;;      
#-------------------No Queued for command line startup.
nq)

        echo "ppp handler, No Queued"
        if [ -r /var/run/$DEVICE.pid ]; then
            echo "ppp on option, system ppp seems to be up"
            if [ ! "$?" = "0" ]; then
               rm -f /var/run/$DEVICE.pid
               echo "ppp0 found to be stale, removing"
            else
               echo "ppp: system ppp is active aborting"
               exit 0
             fi
        else
            echo "pppd found off-line: REinitiating pppd connection"
            /usr/sbin/pppd
            #--Been booted up to 50sec becuase of false reports
        fi
        exit 0 ;;

help)
          echo $0 [options]
          echo "PPP Crontab/command line handler"
          echo " on         Start pppd send queued mail, get mail "
          echo " off        Disconnect pppd"
          echo " nq         same as on, except without check up status"
          echo "             or getting & sending queued mail"
          exit 0 ;;

*)      
        #Note in non release version this calls the old script

          echo "$0 [options]"
          echo "PPP Crontab/command line handler"
          echo " on         Start pppd send queued mail, get mail "
          echo " off        Disconnect pppd"
          echo " nq         same as on, except without check up "
          exit 0
          ;;      
esac

---------------------------end cut----------------------------

--
Grey Cloak

         ---------------------------------------------
  .###########.   Change spamtrap to grycloak, to email me.
 ##'___   ___`##   Wizard.FAQ v2.0 send blank Email to:

 ### ) | | ( ###    For other documents served

   #  ~!!!~  #    

http://www.geocities.com/Area51/7614
http://w3.one.net/~grycloak/dreams/dream.htm

 
 
 

1. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

Is there a proper fixed bash on any of the FTP sites out there?

I know there bash is on the usual sites but I don't know if they are
bugged or not :(

Regards,

Neil.

--


------------------------------------| Edinburgh, EH14 2DE, United Kingdom
**Domino: There`s nothing you can do when you`re the next in line: Domino**

2. freeBSD, WindowMaker and asclock?

3. Help: Need to pass filename to script from C prog

4. Zmodem

5. Passing arguments from the form via BASH script

6. Tape backup (8 mm SCSI Exabyte) support?

7. Passing variables on the command line to a bash script

8. SCSI Problem: Linux 2.0.35 halts when booting Adaptec 2944

9. In the Bash how to pass parameters to a called Perl script

10. Need help with bash script to isolate a portion of an output

11. Need help wirh scripting arrays in bash

12. Need help on bash scripting

13. bash script, need help ! Please!