Operating System - HP-UX
1837962 Members
2596 Online
110124 Solutions
New Discussion

Test if a remote file exists / rcp -i

 
SOLVED
Go to solution
Stephen Mudd
Occasional Contributor

Test if a remote file exists / rcp -i

I want to test if a remote file exists before performing an rcp in a script, so that the user is prompted before overwiting a file (like the -i option on cp). Does anyone have an easy way of doing this, or already have a script to add a '-i' type function to rcp? I'm using HP-UX11i
4 REPLIES 4
John Palmer
Honored Contributor
Solution

Re: Test if a remote file exists / rcp -i

You could code the test for existence of the remote file something like...

REMFILE=$(remsh -n ls 2>/dev/null)

if [[ -z ${REMFILE} ]];
then
else
fi

Regards,
John
Steve Steel
Honored Contributor

Re: Test if a remote file exists / rcp -i

Hi


If you go to

http://hpux.cs.utah.edu/hppd/hpux/Networking/Admin/rsync-2.5.5rc1/

This is rcp with options.

Not yet for 11.11 but 11.00 should run or
rebuild it


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Peter Kloetgen
Esteemed Contributor

Re: Test if a remote file exists / rcp -i

Hi Stephen,

first to say, you can check if a file exists with the following command:

test -f file_name

or

[ -f file_name ]

you could use this in the following construction:

if [ -f file_name ]
then
echo "Do you want to copy this file? \c"
read choice
if [ $choice = "y" -o $choice = "Y"]
then
rcp file_name destination_path
fi
fi

Allways stay on the bright side of life!

Peter

I'm learning here as well as helping
Deepak Extross
Honored Contributor

Re: Test if a remote file exists / rcp -i

Stephen,
The man page for rcp clearly states that if the destination file already exists and is writable then it will be overwritten. I'm afraid you'll just have to script around this to build the -i functionality.