RE: [Nolug] Bash question

From: David John <djohn_at_archdiocese-no.org>
Date: Fri, 20 Apr 2007 13:52:08 -0500
Message-ID: <00ce01c7837c$ff868da0$fe93a8e0$@org>

> -----Original Message-----
> From: owner-nolug@redfishnetworks.com [mailto:owner-
> nolug@redfishnetworks.com] On Behalf Of B. Estrade
> Sent: Friday, April 20, 2007 12:59 PM
> To: nolug@nolug.org
> Subject: Re: [Nolug] Bash question
>
> The only thing I could get to do what you want is:
>
> #!/bin/sh
>
> VAR="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
>
> CONNECT=0
>
> for i in $VAR; do
> ((CONNECT++))
> if [ $i == $1 ]; then
> break
> fi
> done
>
> echo $CONNECT
>
> BTW, I would not use a construct like this in a shell script even if
> it is possible. I didn't realize that this was possible in bash, but
> it is. I tried various ways to expand the value such that it did the
> implied enumeration, but I could not get it to work. If you tell us
> what you are actually trying to do, I am sure someone would be able to
> give you a better way (and language..*cough* ... Perl .. *cough) in
> which to do this sort of thing.
>
> Cheers,
> Brett
>

Thanks Brett. That worked. What I'm trying to do is create a unified
method for SSH'ing into any of the Firewalls in our cluster, since they can
only be contacted through their HA addresses. I suppose this could have
been done with Perl but I'm more comfortable with Bash (and PHP ;-) ). At
any rate, here's what I ended up with in case anyone's interested:

#!/bin/sh
VAR="$1"
CURRENT=$(echo `ls /my/path/THIS_IS_FW*` | sed -e 's/.*\(.\{1\}\)$/\1/')
MATCH=$CURRENT$VAR

showusage() {
        echo -e "Insert usage instructions here...\r"
        exit 1
}

if [ "$CURRENT" == "$VAR" ]; then
        echo "You are already connected to $CURRENT. Exiting..."
        exit 1

elif [[ "$VAR" =~ '[A-Z]' ]]
then
        LETTER="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
        CONNECT=0
        for i in $LETTER; do
                   ((CONNECT++))
                   if [ $i == $VAR ]; then
                             break
                   fi
         done
        echo -e "Connecting to FW$VAR...\r"
        ssh myuser@x.x.x.$CONNECT
else
        showusage
fi

It does what I'm trying to accomplish. Thanks again Brett ;-)

Dave

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 4/19/2007
5:56 PM
 
This message has been scanned by the Internet Service Departments Virus/Spam filter.
___________________
Nolug mailing list
nolug@nolug.org
Received on 04/20/07

This archive was generated by hypermail 2.2.0 : 12/19/08 EST