Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"if" using the -s option to check files 1

Status
Not open for further replies.

vodkadrinker

Technical User
May 16, 2002
163
GB
The following statement works fine to check if a file exists on a local server but is there anyway to use this option to check a remote server?

if [ -s /tmp ]
then
echo "/tmp exists"
else
echo "/tmp does not exist"
fi

Many thanks
VD
 
I guess what I am asking is can you do something like...

if [ -s REMOTESERVERNAME:/tmp ]
then
echo "/tmp exists"
else
echo "/tmp does not exist"
fi

Or can someone suggest another way?

Many thanks
VD
 
man automount

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok thanks for the automount but I think I should be able to use test to set a variable if I run the command via rsh.

Something like....

check=`rsh REMOTESERVERNAME test -s /tmp`

How do I grab the exit value from a test?

So in simple term's if you did a "test -s /tmp" on any server be it local or remote how can i capture the exit value.

test -s /tmp

Many thanks
VD


 
Something like this ?
check=`rsh REMOTESERVERNAME test -s /tmp && echo true`
if test "$check" = true; then
echo "Exists and size greater than zero"
else
echo "Do not exists or null size"
fi

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Many thanks PHV I've been pitching at a similar answer not understanding why it kept comming back with a true answer even if the file/directory does not exist. For anyone using the rsh command make sure you put the remote command in '' otherwise it will not work!!!...

Here's my answer for anyone with a similar problem...

# cat test
check=`rsh REMOTESERVERNAME 'test -s /tmp;echo $?'`
echo ${check}
if [ ${check} = 0 ]
then
echo "exists"
else
echo "don't exist"
fi
check2=`rsh REMOTESERVERNAME 'test -s /tmpppppp;echo $?'`
echo ${check2}
if [ ${check2} = 0 ]
then
echo "exists"
else
echo "don't exist"
fi

# ./test
0
exists
1
don't exist

PHV's answer will also work but needs to be modied like so...

check=`rsh REMOTESERVERNAME 'test -s /tmp && echo true'`
if test "$check" = true; then
echo "Exists and size greater than zero"
else
echo "Do not exists or null size"
fi


Thanks again PHV
Regards
VD :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top