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!

Returning UMASK and Appying to file 1

Status
Not open for further replies.

Autosys

Programmer
Jun 1, 2004
90
0
0
GB
Hello All,

I hope someone can help me. I've got a script that will archive a file. Once this file is archived, it will create a new file with the same name (an empty one).

The script is generic and most of the time the script is executed where only the owner of the file needs to be able to write to it, however, there are instances where the group members need to be able to write to the file as well.

Is there a way to get the UMASK information from the file before it was archived, and then easily apply the same permissions to the new file when creating it?

This is in ksh not Perl.

Hope this makes sense, let me know if it doesn't!

Thanks in advance!

Stefan
 
You could copy the file's permissions using cp -p before archiving it, e.g...
[tt]
cp -p file1 tmp1
gzip file1 [/tt]#---or whatever archive command[tt]
mv tmp1 file1
>file1[/tt]

 
Thanks Ygor,

Though other processes might write to the file at the time and I can't simply move a new file into that directory or move this file out.

My script is doing a touch on the new file to create it if it doesn't exist. I need to apply the proper permissions then to this file after it's been touched ... but I need to know what the permissions of the file was.

Hope this explains it a bit better.
 
Are you sure that you can't just use chmod +rw the file after touching it?
Otherwise you may have to use perl...
[tt]
PERMS=$(perl -e 'printf "%04o",(stat("file1"))[2]&07777')[/tt]
 
Thanks Ygor, I think this Perl command is going to do the trick! Just tested it and it seems to be doing what I need it do!
 
Hi Stefan,

Instead of creating a new file with the same name, why not just "empty" the file, thus preserving its permissions.
eg:
after archiving file1
cp /dev/null file1

Another possibility is to look into ACLs (and the getting and setting of them), depending what flavour of UNIX you are using. Perhaps try man -k acl .

I hope that helps.

Mike
 
Thanks Mike,

I'm still farily new to Unix so it's all very big words to me (ACLs) .. I will certainly look it up though.

I don't want to truncate the file after I copied it because there are quite a few processes all over the place writing to it and I could risk truncating new events that weren't archived.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top