Hi,
First i would like to say that im a unix begginer.
I have a file named /tmp/sample.lst that contain about 20 rows like the following two :
'/tmp/aa.txt' '/temp/aa.txt'
'/tmp/xx.txt' '/temp/xx.txt'
Inside a ksh script i would like to do the following task:
add the cp command at the begging of each line, and after that check if the
copy command successed.
for example:
cp `cat /tmp/sample.lst`
if [ st$ -eq != 0 ]
then
echo "fail"
else
echo "success"
fi
Could one demonstraite how to run through the lines and check if each copy
succeded ?
Thank You Very Much !!!!
#!/bin/ksh
while read sourcefile destfile
do
cp $sourcefile $destfile
if [ -s $destfile ] ; then
echo "$destfile copied successfully from $sourcefile"
fi
done < /tmp/sample.lst
Might be better to test the return code rather than existence of file - this would pick up errors like unable to overwrite existing file because of permissions, lack of space etc, also I'd like a specific error message - but them I'm just picky
if [ $? -eq 0 ] ; then
echo "$destfile copied successfully from $sourcefile"
else
echo "ERROR: failed to copy $destfile from $sourcefile"
fi
done < /tmp/sample.lst