[wplug] BASH question

Bob Schmertz rschmertz at speakeasy.net
Wed Jul 9 16:19:20 EDT 2003


Wise, Jeremey incurred the wrath of Bob on Jul 9, by saying

>Another stupid question. I am trying to write a script that detects if a DSL
>line is down if it is start it. If the IP rotates email it to me so I can
>know how to get to it if I need to.
>
>***************
>#!/bin/bash
># Script to bring up Landmark's Internet
># 07-09-2003
># v0.1
>Internetstatus="adsl-status |grep up|cut -f 4 -d ' '"
>InternetIP="ifconfig ppp0 |grep inet |cut -f 2 -d : |cut -f 1 -d ' '"

You probably want to put this whole thing in back quotes (or $(this) 
notation), rather than double quotes.  On the other hand, if you don't 
want this to be evaluated yet, why don't you just put this line later in 
the script?

>curDate=`date +"%y-%m-%d"`
>curTime=`date +"%H%M"`
>
>if $Internetstatus=up ;then
>   printf The Internet link is up!
>      if [! $InternetIP=(cat /root/CurrentIP.txt)] ;then

Spaces.  There must be a space after the [.  Apparently there musst also 
be spaces on either side of the = comparison operator (while there 
should be no spaces in assignment).  And, looks like you left out a $ 
sign in front of your open parenthesis ( "$(cat /root/CurrentIP.txt)" )

>       echo $InternetIP >/root/CurrentIP.txt
>       echo $InternetIP |mail -s "New IP Address" wisej at pios.com
>      fi
>   ;else
>   echo The Internet link is down:$curDate-$curTime >>/var/log/messages
>fi
>****************
>
>My issues are
>1) I can run the command "ifconfig ppp0 |grep inet |cut -f 2 -d : |cut -f 1
>-d ' '" at a shell prompt and get an ok response but it does not run. I
>tried to put it in brackets (subshell) but that does not work either
>2) Logic does not hold; " if [! $InternetIP=(cat /root/CurrentIP.txt)]
>;then". How does one do this? How can I check a string output against an
>existing variable string or integer?

-- 
Cheers,
Bob Schmertz





More information about the wplug mailing list