[wplug] BASH question

Wise, Jeremey WISEJ at PIOS.com
Wed Jul 9 16:56:23 EDT 2003


Ok so let me see if I understand.

************
# 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 ' '))
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
       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
***********
1) You were saying that to make a variable equal to a string (such as an IP
address) I need to run the whole command in backets ie. Subshell
ex:(ifconfig ppp0 |grep inet |cut -f 2 -d : |cut -f 1 -d ' ') This does work
now... thx.
2) My syntax errors; lack of space, lack of closing bracket did not seem to
fix the next step where I attempt a comparison of $InternetIP to ($(cat
/root/CurrentIP.txt)) and it fails. Is my logic right but syntax wrong?

Thanks,

Jeremey Wise (440)-519-6006
(CNE,MCSE,CSE)
Pioneer-Standard Electronics, Inc
wisej at pios.com

IBM ED PACK -Part # SB033 $4,500 ... SP Discount 11%
IBM ED CARD - Part # SB218 $8,995 ... SP Discount 8.5%

-----Original Message-----
From: Bob Schmertz [mailto:rschmertz at speakeasy.net] 
Sent: Wednesday, July 09, 2003 4:19 PM
To: Wise, Jeremey
Cc: WPLUG
Subject: Re: [wplug] BASH question

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