Operating System - HP-UX
1829563 Members
1478 Online
109992 Solutions
New Discussion

remsh remote directory exist test

 
SOLVED
Go to solution
bin lu_1
Advisor

remsh remote directory exist test

Hi,

My problem is test a directory exist or not

In a remote (name ctcyborg) server , I could test directory locally.

# test -d /home/blu/rvele (a not exist directory)
# echo $?
1
# test -d /home/blu/rvelez
# echo $?
0
# test ! -d /home/blu/rvelez
# echo $?
1

But in peer remote server to ctcyborg, I could not get expected result.

# remsh ctcyborg test -d /home/blu/rvelez
# echo $?
0
# remsh ctcyborg test ! -d /home/blu/rvelez
# echo $?
0

As we promote files from dev machine to production machine. A script could make us operation less-error in typo.
We have to verify the directory exist in remote machine first, then rcp files over.

I could test a remote server directory exist or not. As my following script always abort, even the remote directory exit.

if remsh ctcyborg test ! -d /home/blu/rvelez
then
echo " there is no /home/blu/rvelez directory in ctcyborg, ABORT"
exit 1
fi

Thank you

7 REPLIES 7
RAC_1
Honored Contributor
Solution

Re: remsh remote directory exist test

That is return status of remsh command. you need to to as follows.

remsh ctcyborg 'test ! -d /home/blu/rvelez;echo $?'

Anil
There is no substitute to HARDWORK
bin lu_1
Advisor

Re: remsh remote directory exist test

Anil,

It is great, As I spent alot other combinations. they all do not work today. I got what I expected from you.

# remsh ctcyborg 'test ! -d /home/blu/rvelez; echo $?'
1
# remsh ctcyborg 'test -d /home/blu/rvelez; echo $?'
0

Thanks a lot
Bin
bin lu_1
Advisor

Re: remsh remote directory exist test


I am a newbie in scripting.
But, after I put it in script, it always abort, when 1 come up, it should not execute "then ...fi" block, but

for m in `cat $FILENAME"1"`
do
if remsh ctcyborg 'test ! -d /home/blu/rvelez; echo $?'
then
echo " there is no /home/blu/rvelez directory in ctcyborg, ABORT"
exit 1
fi
rcp -p /home/blu/$m ctcyborg:/home/blu/rvelez/$m


output below with first line -x option

+ remsh ctcyborg test ! -d /home/blu/rvelez; echo $?
1
+ echo there is no /home/blu/rvelez directory in ctcyborg, ABORT
there is no /home/blu/rvelez directory in ctcyborg, ABORT
+ exit 1

This happened when there is a /home/blu/rvelez directory in ctcyborg server.

Thanks,

Biswajit Tripathy
Honored Contributor

Re: remsh remote directory exist test

That's because remsh command still returns
success even if the directory does not exists. You
need to catch the 'echo $?' part in the remsh
command see if it's zero. Change the script to
following:
-------
for m in `cat $FILENAME"1"`
do
tmp=$(remsh ctcyborg 'test ! -d /home/blu/rvelez; echo $?')
if [ $tmp -eq 0 ]
then
echo " there is no /home/blu/rvelez directory in ctcyborg, ABORT"
exit 1
fi

- Biswajit
:-)
bin lu_1
Advisor

Re: remsh remote directory exist test

Biswajit,

Your point makes the script behaviour on the track. Then it brought my question to the end.

Thank you very much,

Bin
Suraj Singh_1
Trusted Contributor

Re: remsh remote directory exist test

Seems u got the answer.... Where are the points...
What we cannot speak about we must pass over in silence.
bin lu_1
Advisor

Re: remsh remote directory exist test

Thank you all here involve this topic, it was my first created thread here. I just submitted the points which I did not pay attention before.

Now, I know how I should do here.