usage of case statement in place of IF elif...

Hi,

I need to carry out the back up of the data if exists...(file size not equal to zero)

i tried in this way but it is not successful....where am making the mistakes? and if possible can i use case syntax in place of "if"

#!/bin/ksh
filename=`TZ=CST+24 date +%Y%m%d`
ZERO=0
SIZE_64=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-64.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_71=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-71.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_72=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-72.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_73=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-73.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_80=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-80.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_EZ=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-EZ.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_WZ=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-WZ.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_NZ=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-NZ.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_MTNL=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-MTNL.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_COUNT=$(ls -ltr /aemu/ErrorLogs/data/MissingCGIcount.txt | tr -s ' ' | cut -d ' ' -f 5)



if [ $SIZE_64!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-64.txt /aemu/ErrorLogs/backup/CHN/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-64.txt > /aemu/ErrorLogs/data/MissingCGI-64.txt

elif [ $SIZE_71!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-71.txt /aemu/ErrorLogs/backup/KTK/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-71.txt > /aemu/ErrorLogs/data/MissingCGI-71.txt
        
elif [ $SIZE_72!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-72.txt /aemu/ErrorLogs/backup/KER/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-72.txt > /aemu/ErrorLogs/data/MissingCGI-72.txt

elif [ $SIZE_73!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-73.txt /aemu/ErrorLogs/backup/AP/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-73.txt > /aemu/ErrorLogs/data/MissingCGI-73.txt

elif [ $SIZE_80!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-80.txt /aemu/ErrorLogs/backup/TN/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-80.txt > /aemu/ErrorLogs/data/MissingCGI-80.txt
        
elif [ $SIZE_EZ!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-EZ.txt /aemu/ErrorLogs/backup/EZ/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-EZ.txt > /aemu/ErrorLogs/data/MissingCGI-EZ.txt

elif [ $SIZE_WZ!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-WZ.txt /aemu/ErrorLogs/backup/WZ/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-WZ.txt > /aemu/ErrorLogs/data/MissingCGI-WZ.txt
        
elif [ $SIZE_NZ!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-NZ.txt /aemu/ErrorLogs/backup/NZ/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-NZ.txt > /aemu/ErrorLogs/data/MissingCGI-NZ.txt
        
elif [ $SIZE_MTNL!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-MTNL.txt /aemu/ErrorLogs/backup/MTNL/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-MTNL.txt > /aemu/ErrorLogs/data/MissingCGI-MTNL.txt
        
else [ $SIZE_COUNT!=$ZERO ]
        cp /aemu/ErrorLogs/data/MissingCGIcount.txt /aemu/ErrorLogs/backup/COUNT/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGIcount.txt > /aemu/ErrorLogs/data/MissingCGIcount.txt
        
fi

exit

Aemunathan

From what I can tell, you should have spaces around " != " as in

[ $SIZE_64 != $ZERO ]

Hi

If any one condition satisfied in the if statement, it come out of all the conditional loops...
in this case it come out after executing first if statement...eventhough other conditions are also true.
What could be the issue?

I think that is the functionality of else-if ladder. It will check the first if condition, if its false goes to next if (elif) condition, if its false next elif condition or if the condition returns true it comes out of whole if.

If all the conditions are getting false then it will execute the else part.

If you want your script to execute all the if conditions use

if ..
then
.
.
.
fi

for each checking.