Operating System - HP-UX
1834297 Members
2033 Online
110066 Solutions
New Discussion

Re: variable from remote shell

 
Shahul
Esteemed Contributor

variable from remote shell

Hi,

A small questiona here, may be a silly one.
I am running some condition checks in remsh, For both the conditions, I need to get a variable exported to my local shell. Confused??!!!! Here is the command

#remsh Rsystem "if [ -z "string" ];then;FLAG="Y";else;FLAG="N";fi"

#echo $FLAG (Yes, definitely it's going to be null).

How can I get this value from remsh?

TIA
Shahul
3 REPLIES 3
Muthukumar_5
Honored Contributor

Re: variable from remote shell

FLAG=$(remsh Rsystem "if [ -z "string" ];then;FLAG="Y";else;FLAG="N";fi;echo $FLAG")

Now try as,

echo $FLAG

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: variable from remote shell

Try as,

# FLAG=$(remsh localhost -l root -n 'if [ ! -z "string" ];then FLAG="Y";else FLAG="N";fi;echo $FLAG;')
# echo $FLAG
Y

or another way as,

# remsh localhost -l root -n 'if [ ! -z "string" ];then FLAG="Y";else FLAG="N";fi;echo $FLAG;' | grep -w 'Y'

hth.
Easy to suggest when don't know about the problem!
CAS_2
Valued Contributor

Re: variable from remote shell

I think the use of FLAG in the remote command is unnecessary because the value of FLAG is needed in the local shell, NOT in the remote shell. In other words, your local shell has to read a value printed by the remote command.

#remsh Rsystem 'if [ -z "string" ]; then; echo Y; else; echo N; fi' | read FLAG
#echo $FLAG

Or, as others wrote:

#FLAG=$(remsh Rsystem 'if [ -z "string" ]; then; echo Y; else; echo N; fi')
#echo $FLAG

P.D: the first one doesn't work on BASH shell.