Re: [Nolug] Bash question

From: B. Estrade <estrabd_at_gmail.com>
Date: Fri, 20 Apr 2007 19:05:22 +0000
Message-ID: <a7ee76680704201205k3279a2c4sd951b0c40a2b9fe7@mail.gmail.com>

On 4/20/07, David John <djohn@archdiocese-no.org> wrote:
> > -----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 ;-)

And that is the important thing :) ... glad it worked.

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
>

-- 
225.578.1920
AIM: bz743
http://www.loni.org/
estrabd@lsu.edu
estrabd@gmail.com
___________________
Nolug mailing list
nolug@nolug.org
Received on 04/20/07

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