Operating System - HP-UX
1833756 Members
2487 Online
110063 Solutions
New Discussion

How do you check if file exists on remote system?

 
Doug Moloney
Occasional Advisor

How do you check if file exists on remote system?

I am trying to write a shell script that basically does

if [ -f //remotehost/tmp/HP* ]
then
echo "HP files found"
fi

or
if [ -f remotehost:/tmp/HP* ]
then
echo "HP files found"
fi

But neither work, can someone please help?
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: How do you check if file exists on remote system?

Here is what I would do:
#If the file, or files, are found then VAR1 will not equal 0
VAR1=`remsh remotesystem "ll /tmp/filename" | wc -l`

if [ VAR1 != 0 ]
then
echo "File(s) exist"
else
echo "File Not Found"
fi
Rita C Workman
Honored Contributor

Re: How do you check if file exists on remote system?

Hmm...I'm sure others will have more ideas. But I would probably execute a remsh in my script to go out and run a job/script on the remote host. Now that remote script would be a simple find command and then you could just re-route the output to the first server and write it there

find / your_commands > first_server:/dir/output.file

Just a thought,
/rcw
Doug Moloney
Occasional Advisor

Re: How do you check if file exists on remote system?

Not quite, Patrick's was close but right..

ora_svr @ [/u01/app/oracle/admin]# more test.sh
VAR1=`remsh zakori "ll /tmp/doug" | wc -l`

if [ VAR1 != 0 ]
then
echo "File(s) exist"
else
echo "File Not Found"
fi

ora_svr @ [/u01/app/oracle/admin]# sh test.sh
/tmp/doug not found
File(s) exist

Patrick Wallek
Honored Contributor

Re: How do you check if file exists on remote system?

the if statement should be:

if [ $VAR1 != 0 ]