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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying File Permissions in Bourne 1

Status
Not open for further replies.

Arluin

IS-IT--Management
Jan 6, 2003
19
0
0
US
Does anyone know how to copy one files permission mask to another file in Bourne shell?

I'm setting up a script to rollover logs in /var/adm. I want to touch new copies of the log files and then set their privilege masks (and ownership) to be the same as the original log files settings.
 
A bit of a hack but you could "cp -p" the original file to the new file and then empty it out with "cat /dev/null > $FILE".

Otherwise I think you are going to have to get the output from an "ls -l" and use that to figure out what the permissions and ownership should be.
 
Thanks for responding. That meets the requirements. I don't 'like' the fact that I'm inheriting old file date/times, but that is not germane.
 
Arluin,

I would think doing the &quot;cat /dev/null > <new_log>&quot; would change the modified time, but if it does not, you might use the following...

NEW_DATE=`date +%m%d%H%M%y`

cp -p <old_log> <new_log>
cat /dev/null > <new_log>
touch -m $NEW_DATE <new_log>


Good Luck. Have a Great Day!! :)
~Sol
Sys Admin
 
Alternatively:

[tt]getfacl originalfile | setfacl -f - copiedfile[/tt] Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top