Results 1 to 4 of 4
Hi All,
I am new to scripting, would like to have a script that tests whether a directory exists on remote host & display the message accordingly. The remote hostname ...
- 01-18-2011 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 6
Shell script to check whether directory exists on remote server
Hi All,
I am new to scripting, would like to have a script that tests whether a directory exists on remote host & display the message accordingly. The remote hostname can be provided by means of file containing list of hostnames. Can use rsh for connecting to remote host.
I tried with couple of scripts by searching google but didn't get desired result. Please help me, below is my efforts, $file contains list of hostnames.
for i in $file
do
if ( [ `rsh $i test -d /tmp/.X*` ] || [ `rsh $i test -d /scratch/.X*` ] )
then
echo "directory exist"
else
exit 0;
fi
done
Thanks in advance, appreciate all the efforts.
- 01-18-2011 #2
I would use ssh instead of rsh - rsh is unsecured and very old.
localhost#ssh user@remote "[ -d /tmp ]"
localhost#echo $?
localhost#ssh user@remote "[ -d /xyz ]"
localhost#echo $?- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 01-18-2011 #3Just Joined!
- Join Date
- Aug 2010
- Posts
- 6
I agree ssh is more secure than rsh, would like to test the condition whether directory exists on remote server & also display message accordingly if it exists, the condition has to be run inside a loop as the number of hosts to be tested are many & hostnames are passed as $file in the script.
Thanks for the help.
- 01-18-2011 #4
Can you create passwordless ssh login ?
Try "pdsh" thats more powerful than rsh or ssh.for i in {1..10};
do
ssh user@client$i "[ -d /xyz ]"
if [$? -eq 0]
then
echo "exists"
fi
done- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote
