Operating System - HP-UX
1830939 Members
1655 Online
110017 Solutions
New Discussion

Valuating remote values ...

 
SOLVED
Go to solution
Manuales
Super Advisor

Valuating remote values ...

Hi ..
how can i to valuate remote answers, i mean, i'm valuating the following:

if [[ ! -s `remsh $ip_test_server_atlun31 "uname -a;/usr/bin/ls /interface/${a}/${z}"` ]] ; then
remsh $ip_test_server_atlun31 "uname -a;/usr/bin/mkdir /interface/${a}/${z}"
fi

if i do above written , can i know if the remote folder exist?

i run that and i could system could not work well because answer to me that directories already exist ...

mkdir: cannot create /interface/AM/LOG: File exists

please let me know.
Thanks.
4 REPLIES 4
John Kittel
Trusted Contributor

Re: Valuating remote values ...

if I correctly understand what you are trying to do, your syntax that starts with:

if [[ ! -s `remsh ...

is trying to use the local shell's -s Conditional Expression operator to test the existence of the file (or directory)...

but it won't work that way. It is going to test for a file on the local system, I guess a file with the name(s) if any returned by the remsh uname and ls commands. But then if your if statement evaluates you're trying to run a mkdir command to create a directory on the remote system.

You need a different approach...
James R. Ferguson
Acclaimed Contributor
Solution

Re: Valuating remote values ...

Hi Manuales:

Collect the return status of your test for the presence of a directory on the remote server in a _local_ file. Then read the local file and examine the return code from the test made on the remote server. For example:

remsh somehost -n '[ -d /somehost_dir ];echo $?' > /tmp/result

[ "$(< /tmp/result)" != 0 ] && echo "dir is absent" || echo "dir is present"

Regards!

...JRF...
Manuales
Super Advisor

Re: Valuating remote values ...

James, thanks a lot !!!
you know i did the following:

v=`remsh $ip_test_server_atlun31 "uname -a;/usr/bin/ls -d /interface/${a}/${z}" | grep -v HP-UX`
if [[ $v != "/interface/${a}/${z}" ]]; then
remsh $ip_test_server_atlun31 "uname -a;/usr/bin/mkdir /interface/${a}/${z}"
fi


any way i have learnt other way for doing it .. the way that you have told me !!!

:0) .... thanks.
Dennis Handly
Acclaimed Contributor

Re: Valuating remote values ...

If you are doing something complicated, you might run the script on the remote machine and only send a completion status back.

In the above case, you would pass in $a and $z to your remote script and it would do the mkdir.

Or better yet, just do mkdir -p, and you don't care if it already exists.