Operating System - HP-UX
1753835 Members
8279 Online
108806 Solutions
New Discussion юеВ

Re: Remote Copy Putting Wrong File Permissions on Target

 
SOLVED
Go to solution
Laurie A. Krumrey
Regular Advisor

Remote Copy Putting Wrong File Permissions on Target

Hi All,

I couldn't get anyone to answer me, so I started a new tread (hope that's OK - more points).

Anyway, it is creating the file with root and
sys and not syb115 syb115 and I tried the
rcp with and without the -p and it makes no
difference.

It does NOT keep the
same file permissions and owner and group.
It does this:
rw------- 1 root sys 12242402 May 14 21:41 laurie

When it should leave the permissions to the
orginial file:

-rw------- 1 syb115 syb115 460911 May 14 21:00 masterbk1.gz

Anyway clues what I am doing wrong?

Laurie

My Script:

FILES="/db01/syb115/backup/*.gz /db02/syb115/backup/*.gz etc"

for FILE in ${FILES}
do
rcp -p ${FILE} snoopy:${FILE}
done
~


Happiness is a choice
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Remote Copy Putting Wrong File Permissions on Target

Hi Laurie,

Actually -p is keeping the correct permissions
along with modification times. It is not keeping ownership - that is a function of the
user invoking the rcp (or remsh) commands.
You have two choices:
1) Set up the desired user as a valid cron user; setup .rhosts (and possibly /etc/hosts.equiv) for that user
or
2) after each rcp -p in your loop
do a remsh snoopy chown syb115:syb115 $FILE

Hope this clears up your problem, Clay
If it ain't broke, I can fix that.
Shannon Petry
Honored Contributor

Re: Remote Copy Putting Wrong File Permissions on Target

The problem is just a slight error in your logic of what the -p option is doing.

The -p option only keeps the "mod" the same. I.E.
755=rwxr-xr-x
A file with the 755 permission bit's set will get copied with 755 permissions as the permissions request is made After the copy.

The problem is who owns the files. By nature a unix file is always owned by the user who created it and their primary group.

If you want that user to own the files on the other system, they will have to be the one who issues the rcp command.

Make sure that the user can rcp data, and the ID exists on the other system. If this is a cron job, make sure to give them and entry in /usr/lib/cron/cron.allow.

If you dont want to do this, then extend your script to remote shell over and chown and chgrp the file to the owner you want when the copy is done.

Hope it helps!
Shannon
Microsoft. When do you want a virus today?
Peggy Fong
Respected Contributor

Re: Remote Copy Putting Wrong File Permissions on Target

The permissions look the same unless I missed something in your post. As for ownership and group, does the owner and group exist on the remote server with the same UID and GID in passwd file (assuming not NIS or trusted system)?

Peggy
Nico van Royen
Frequent Advisor

Re: Remote Copy Putting Wrong File Permissions on Target

As far as I know rcp will always set the user to the user executing the rcp command, you can only preserve the permission flags itself.

You might try the following (tested and works)..

#!/usr/bin/ksh

files="/tmp/file1 /tmp/file2"

for file in $files
do
tar cvf ${file}.tar ${file}
rcp ${file}.tar otherhost:${file}.tar
remsh otherhost tar xvf ${file}.tar
remsh otherhost rm ${file}.tar
rm ${file}.tar
done

Might not be the prettiest way, but it gets the job done..:)

Nico van Royen
If all else fails, try reading the manual...
MARREEL Chris_1
Regular Advisor

Re: Remote Copy Putting Wrong File Permissions on Target

I never use RCP, especialy because the original file-permissions are lost.
I allways use tar in combination with remsh.
Your need could be filled with the following command :

# cd /db01/syb115/backup
# tar cvf - *.gz | remsh snoopy "(cd /otherdirectory ; tar xvf - )"

I always use such a structure of command, and this gives me the possiblity to copy the files *.gz into another directory on the other machine.

eventualy you can use it without the v (verbose) option of tar.

I once had to copy a lot of ASCII-files (*.log) over a slow WAN-connection, so I used compress to compress the standard output (and uncompress the standard input) :

cd /tmp
tar cvf - *.log |compress| remsh snoopy "(cd /tmp ; cat - | uncompress | tar xf - )"


Greetings,
Chris MARREEL