I do this in GNU, I guess it would work on Solaris too:
touch new_file && chmod --reference=old_file new_file
Frage
What is the best way to create a new, empty file that has the same ownership and perms as an existing file for a Solaris /bin/sh shell script?
This is for rotating a log file away for compression and dump storage.
At the moment I am using:
mv log log_ts && cp -p log_ts log && cp /dev/null log
Is there a better way to do it?
Update: Unfortunately this is on a conservatively built live Sol10 server and no gnu fileutils are available.
Lösung
I do this in GNU, I guess it would work on Solaris too:
touch new_file && chmod --reference=old_file new_file
Andere Tipps
You will need do something like this:
PERM=`ls -l $EXISTING | cut -d" " -f1 | cut -c2- `
PERMU=`echo $PERM |cut -c1-3 | sed s/-//g`
PERMG=`echo $PERM |cut -c4-6 | sed s/-//g`
PERMO=`echo $PERM |cut -c7-9 | sed s/-//g`
chmod u="$PERMU" $TARGET
chmod g="$PERMG" $TARGET
chmod o="$PERMO" $TARGET
Naturally this is for Solaris.