Re: Simple scripting issue that's got me stumped right now (151 Views)
Reply
Regular Advisor
S.Rider
Posts: 216
Registered: ‎02-02-2004
Message 1 of 8 (151 Views)
Accepted Solution

Simple scripting issue that's got me stumped right now

/usr/sbin/swlist | grep CPB | sort | tail -1
works fine on my local server

But if I set a variable equal to the command
export CMD1="/usr/sbin/swlist | grep | sort | tail -1"
and then "$CMD1", it's not recognizing the pipe symbols and I get errors about "software | not found" and "sofware grep not found" etc.

But a "remsh xxxxxxx $CMD1" works fine.

I'm trying to get a script that will issue the same command on both the local server and a list of remote servers and I'm stumped why it's being treated differently on the local server.

Ride Boldly Ride, but watch out for El Dorado's
Please use plain text.
Honored Contributor
Alex Lavrov.
Posts: 1,270
Registered: ‎11-16-2002
Message 2 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

Interesting ....

try:
export CMD1='/usr/sbin/swlist | grep | sort | tail -1'


(' instead of ")
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Please use plain text.
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 3 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

Use single quotes.
There is no substitute to HARDWORK
Please use plain text.
Honored Contributor
Alex Lavrov.
Posts: 1,270
Registered: ‎11-16-2002
Message 4 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

Hey, just tried it on linux (don't have hp here) it's acting the same.

Single quote didn't help, but:

export CMD1="/usr/sbin/swlist | grep | sort | tail -1"
sh $CMD1

worked fine.


that's why it works with "remsh", it's just like running it with "sh".
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Please use plain text.
Trusted Contributor
Cesare Salvioni
Posts: 110
Registered: ‎02-14-2002
Message 5 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

hi

try this:
CMD1="/usr/sbin/swlist | grep | sort | tail -1"
eval $CMD1

the problem is that you must force the shell to eval the line twice, the first one to substitute the variable, second one to exec the pipe. Is like:

a="echo b=test"
eval $a

or

eval $(resize) in a xterm

hope it helps
Please use plain text.
Honored Contributor
Biswajit Tripathy
Posts: 508
Registered: ‎12-11-2004
Message 6 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

Interestingly, the "problem" is with pipe. You could use
set CMD="ls -al" and run $CMD and it works fine.

- Biswajit
:-)
Please use plain text.
Regular Advisor
S.Rider
Posts: 216
Registered: ‎02-02-2004
Message 7 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

Thanks guys, fixed in minutes for me.
Single quotes didn't help, "sh $CMD1" kept giving me "execute permission denied" but "eval $CMD1" worked great.
Ride Boldly Ride, but watch out for El Dorado's
Please use plain text.
Honored Contributor
Biswajit Tripathy
Posts: 508
Registered: ‎12-11-2004
Message 8 of 8 (151 Views)

Re: Simple scripting issue that's got me stumped right now

Another option is

alias CMD1="/usr/sbin/swlist | grep | sort | tail -1"
CMD1

- Biswajit
:-)
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation