We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2015-02-26
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
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE