We help IT Professionals succeed at work.

read a line from a file and convert to a command in ksh

I am reading a file from a while loop (tested and it's reading it correctly, line by line), I'm just trying to convert the line into a command by adding "cp" in front of it and it's trying to execute the string.  The format of the file being read is:

./default/passwd /etc/default/passwd
inetd.conf /etc/inetd.conf
syslog.conf /etc/syslog.conf
shadow /etc/shadow
passwd /etc/passwd
group /etc/group
./default/login /etc/default/login
logadm.conf /etc/logadm.conf
profile /etc/profile
.ndel /etc/.ndl
.nodirect.sh /etc/.nodirect.sh

Here's the piece of code where I'm trying to add cp to the line, i.e., I want the first line to execute:
cp ./default/passwd /etc/default/passwd

while read line
ofile=print $line|awk '{print $2}'
         [ -f "$ofile" ] && mv $ofile $ofile.orig
         cp $line
         step="Copying standard $ofile" | tee -a ${SUCCESSLOG} ${FAILLOG}
done < ${MNT}/scripts/zone.etcfiles

Open in new window

Here's the errors I'm getting:
./Solaris_11.finish.final: line 336: ./default/passwd: cannot execute [Permission denied]
./Solaris_11.finish.final: line 336: inetd.conf: not found
./Solaris_11.finish.final: line 336: syslog.conf: not found
./Solaris_11.finish.final: line 336: shadow: not found
passwd: User unknown: /etc/passwd
./Solaris_11.finish.final: line 336: group: not found
./Solaris_11.finish.final: line 336: ./default/login: cannot execute [Permission denied]
./Solaris_11.finish.final: line 336: logadm.conf: not found
./Solaris_11.finish.final: line 336: profile: not found
./Solaris_11.finish.final: line 336: .ndl: not found
./Solaris_11.finish.final: line 336: .nodirect.sh: not found
Watch Question

Most Valuable Expert 2014
Top Expert 2015
while read ifile ofile
         [ -f "$ofile" ] && mv $ofile $ofile.orig
         cp $ifile $ofile
        step="Copying standard $ofile" | tee -a ${SUCCESSLOG} ${FAILLOG}
done < ${MNT}/scripts/zone.etcfiles


Once again, exactly what I need.  Thanks, ozo!