Error in the script

Hi,

I have a test script which zips the log files in a folder.

#!/bin/ksh

cd /home/rt/Test_Zip

z=`ls *.log`
 
for i in $z 
gzip $i > "$i"_`date +%m%d%y`.gz
done

The folder has 4 log files, When I run the script, It ends up with only zipping 2 files that are smaller in size. For other 2 files an error is thrown as below-

s0989pdv:/home/rt$ ./Logs_Zip.sh
detailLog_22Mar.log[1]: [main@: not found [No such file or directory]
detailLog_22Mar.log[2]: DetailedFile: not found [No such file or directory]
detailLog_22Mar.log[4]: [main@: not found [No such file or directory]
detailLog_22Mar.log[5]: Command: not found [No such file or directory]
detailLog_22Mar.log[6]: PRTMSGDM: not found [No such file or directory]
detailLog_22Mar.log[8]: [main@: not found [No such file or directory]
detailLog_22Mar.log[9]: MACHINE: not found [No such file or directory]
detailLog_22Mar.log[10]: -------------------: not found [No such file or directory]
detailLog_22Mar.log[11]: Host: not found [No such file or directory]
detailLog_22Mar.log[12]: System: not found [No such file or directory]
detailLog_22Mar.log[13]: Num: not found [No such file or directory]
detailLog_22Mar.log[15]: OS: not found [No such file or directory]
detailLog_22Mar.log[16]: --------------: not found [No such file or directory]
detailLog_22Mar.log[17]: OS: not found [No such file or directory]
detailLog_22Mar.log[18]: OS: not found [No such file or directory]
detailLog_22Mar.log[20]: LIMIT: not found [No such file or directory]
detailLog_22Mar.log[21]: -----------------: not found [No such file or directory]
detailLog_22Mar.log[22]: Core: not found [No such file or directory]
detailLog_22Mar.log[23]: Data: not found [No such file or directory]
detailLog_22Mar.log[24]: File: not found [No such file or directory]
detailLog_22Mar.log[25]: Max: not found [No such file or directory]
detailLog_22Mar.log[26]: Open: not found [No such file or directory]
detailLog_22Mar.log[27]: Stack: not found [No such file or directory]
detailLog_22Mar.log[28]: CPU: not found [No such file or directory]
detailLog_22Mar.log[30]: JAVA: not found [No such file or directory]
detailLog_22Mar.log[31]: ---------------: not found [No such file or directory]
detailLog_22Mar.log[32]: Java: not found [No such file or directory]
detailLog_22Mar.log[33]: Java: not found [No such file or directory]
detailLog_22Mar.log[34]: Java: not found [No such file or directory]
detailLog_22Mar.log[35]: Java: not found [No such file or directory]
detailLog_22Mar.log: line 35: syntax error at line 36: `(' unexpected
Temp.log[1]: Tue: not found [No such file or directory]
Temp.log[2]: Running: not found [No such file or directory]
Temp.log: line 3: Tue: not found

Please help me...

(a) why do you use the "d=gzip..." and not just "gzip..."?
(b) the redirect ">" is sending any screen output to a file even though your are calling it blah.gz
(c) how big are the log files that are successful vs. the two the script is not successful with

Hi,

I've edited the code.

#!/bin/ksh

cd /home/rt/Test_Zip

z=`ls *.log`

for i in $z
do
gzip $i > "$i"_`date +%m%d%y`.gz
done

Now there is no error,
Now the new problem is-
say I've 4 files test1,test2,test3,test4(All are log files),
the above code results in 8 zip files(replacing original files),
among the 8, 4files are with datestamp having size 0 and other 4 are with variable size names without datestamp.

Why is it happening so?

You need to quote your $z.

date=`date +%m%d%y`
for f in *.log; do gzip "$f"; mv ${f}.gz ${f}_${date}.gz; done

Thanks agn...

That works...
And 1 more thing is how to keep the original files as it is using gzip? so that I can only move the .gz files to another folder?

Check gzip's -o and -c flags.