copy permissions and owners from another unix

this script will generate 2 scripts “chown_cmds.bash” and “chmod_cmds.bash” from a find -ls output, those 2 scripts can be used to set permissions and ownership to files copied to another server

!/bin/sh

>/root/chown_cmds.bash
>/root/chmod_cmds.bash
echo "set -x " >> /root/chown_cmds.bash
echo "set -x" >> /root/chmod_cmds.bash

find /interfacestst -ls | grep -i '/' > /tmp/lsf

cat /tmp/lsf | awk '{ print "chown "$5":"$6" \""$NF "\"" }' > /root/chown_cmds.bash

(
cat /tmp/lsf | while read l;do
perms=echo $l | awk '{ print $3 }'
f=echo $l | awk '{ print $NF }'
OWNER=$(echo $perms | sed -e "s/.(…)./\1/" | sed -e "s/[-]//g" ) GROUP=$(echo $perms | sed -e "s/….(…)./\1/" | sed -e "s/[-]//g" )
OTHER=$(echo $perms | sed -e "s/…….(…).*/\1/" | sed -e "s/[-]//g" )
echo "chmod u=${OWNER},g=${GROUP},o=${OTHER} ${f}"
done
) |tee /root/chmod_cmds.bash