- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Check the directory exist
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2005 06:35 PM
07-01-2005 06:35 PM
rsh remote_host -n "ls -ld /tmp/abcde"
if [ $? != 0 ]
then
echo "connect OK"
else
echo " Connect Not OK !!"
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2005 06:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2005 07:29 PM
07-01-2005 07:29 PM
Re: Check the directory exist
I tried your method , there is error message but still pop "connect OK" , it is strange , could suggest what is wrong ? thx
ls: /tmp/abcde: No such file or directory
Connect OK!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2005 08:27 PM
07-01-2005 08:27 PM
Re: Check the directory exist
Your exit code is coming 0 because its that of "rsh" and not "ls".
Your rsh is running fine and that's why its giving the exit code of 0.
Try it and let us know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2005 08:38 PM
07-01-2005 08:38 PM
Re: Check the directory exist
As your scripts shows is that if the command on remote host fails then it will echo a message "connect ok" and if successed then it will say "connect not ok'. So you have just to delete the "!" from your script and it will work. Just write as
remsh
if [ $? = 0]
then
echo "Connect OK"
else
echo "Connect Not OK"
fi
If you run this script, you will get the line showing your directory and connect ok in case if it exists. And if /tmp/abcde not exists you will get /tmp/abcde not found along with the message connect not ok.
Try this and hope it will work for you.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2005 09:02 PM
07-01-2005 09:02 PM
Re: Check the directory exist
Hi hangyu in my last reply by mistake I have written in the result out put connect not ok but it is connect ok. You are getting connect ok each time because your remsh is always running successfully and it is giving 0 value for $? each time so it is showing connect ok. You can write your script as below
remsh host_name -n "ll -ld /tmp/abcde" | grep "not found"
if [ $? = 0 ]
then
echo "directory not exists"
else
echo "directory exists"
fi
Here actually you have to check for the result of command 'remsh' not the exit status of command 'remsh'.
Try this and I hope it will work now.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2005 05:46 AM
07-02-2005 05:46 AM
Re: Check the directory exist
Dont you feel that $? is showing you the exit status of rsh command rather than you ls -ld command.
I think manoj`s script should work.
Cheers!!!
eknath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 01:47 AM
07-03-2005 01:47 AM
Re: Check the directory exist
may I quote from man remsh:
Note that the return value of remsh bears no
relation to the return value of the remote command.
So it's better not to rely on the return code of the remsh command since it only tells you something about its socket state.
Why don't you do something like this?
rc=$(remsh remote_host '[ -f /some/file/there ] && echo ok')
if [[ $rc = ok ]]; then
echo "remote file present"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 07:19 AM
07-03-2005 07:19 AM
Re: Check the directory exist
This should work:
STAT=$(remsh remote_host "test -d /xxx/mydir; echo \${?}")
if [[ ${STAT} -eq 0 ]]
then
echo "Directory exists"
else
echo "Directory does not exist; status ${STAT}"
fi
Note the \ before ${?}.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 07:20 AM
07-03-2005 07:20 AM
Re: Check the directory exist
STAT=$(remsh remote_host "test -d /xxx/mydir; echo \${?}")
if [[ ${STAT} -eq 0 ]]
then
echo "Directory exists"
else
echo "Directory does not exist; status ${STAT}"
fi
Note the \${?}.