Today I have been working for one of my customers on a script that for a bunch of files matching a glob will read each file, process it, and generate some output into a new file.
I need the output files to have the same permissions and ownership as their respective sources, and started to look into different more or less elaborate ways of doing that. But then it turns out that this is a very well solved problem already. Both chmod and chown have an option for this:
--reference=RFILEuse RFILE's owner and group rather than specifying OWNER:GROUP values
So in my script have added two lines, and now the permissions and ownership are copied onto the new files
I guess these options have been there for years and years, waiting for me:-)chmod ${DSTDIR}/${LOGFILE} --reference=${LOGFILE}chown ${DSTDIR}/${LOGFILE} --reference=${LOGFILE}
No comments:
Post a Comment