cancel
Showing results for 
Search instead for 
Did you mean: 

Help to improve ksh script

SOLVED
Go to solution
zap_2
Advisor

Help to improve ksh script

Dear my friends,

I have below script:

if [ "$x" != "0" ]; then
cat $y | while read LINE
do
cp -p $z${LINE} /eva/bulk/tmp/${LINE}
diff $z${LINE} /eva/bulk/tmp/${LINE}> /dev/null
if [ $? -eq 0 ]; then
gzip /eva/bulk/tmp/${LINE}
else
continue
fi
done

else echo "There are no files to be copied................."
fi

How to reexecute the cp command again with the same line that have diff not equal to zero??Please advice.Thanks in advanced.
7 REPLIES
Kenan Erdey
Honored Contributor

Re: Help to improve ksh script

Hi,


if [ "$x" != "0" ]; then
cat $y | while read LINE
do

is_ok=1

until [ $is_ok -eq 0 ]; do
cp -p $z${LINE} /eva/bulk/tmp/${LINE}
diff $z${LINE} /eva/bulk/tmp/${LINE}> /dev/null
is_ok=$?
done

gzip /eva/bulk/tmp/${LINE}

else echo "There are no files to be copied"
fi


not tested it can be syntax problems.

Kenan.
Computers have lots of memory but no imagination
Dennis Handly
Acclaimed Contributor

Re: Help to improve ksh script

>How to reexecute the cp command again with the same line that have diff not equal to zero?

Did you see my response to your other thread?
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1339591

You could use "cmp -s" instead of diff.
zap_2
Advisor

Re: Help to improve ksh script

Many thanks Keenan and Handy, the above script have improved much.How to test the gzip has gzipped successfully?Please advice.
Dennis Handly
Acclaimed Contributor

Re: Help to improve ksh script

>How to test the gzip has gzipped successfully?

You could just test the exit status, "$?".
Kenan Erdey
Honored Contributor
Solution

Re: Help to improve ksh script

man gzip:

Exit status is normally 0; if an error occurs, exit status is 1. If a
warning occurs, exit status is 2.

you can check after gzip command

if [ $? -eq 0 ]; then
sucessfull
else
not successfull
fi


Computers have lots of memory but no imagination
Arturo Galbiati
Esteemed Contributor

Re: Help to improve ksh script

Hi zap,
instead of:
if [ "$x" != "0" ]; then
cat $y | while read LINE
do
cp -p $z${LINE} /eva/bulk/tmp/${LINE}
diff $z${LINE} /eva/bulk/tmp/${LINE}> /dev/null
if [ $? -eq 0 ]; then
gzip /eva/bulk/tmp/${LINE}
else
continue
fi
done

better:
while read LINE
....
done <$y

HTH,
Art
Kenan Erdey
Honored Contributor

Re: Help to improve ksh script

also,

you can gzip -t for compressed file integrity. but again you must check return value by the script abowe if it returns 0.
Computers have lots of memory but no imagination