Counter

if [ $(stat --printf="%s" /var/log/mrnet.log ) -gt 5000 ] ;then
        echo "mrnet greater 5000"
        gzip /var/log/mrnet.log
        mv /var/log/mrnet.log.gz /var/log/mrnet.log.1.gz
   if [[ -e /var/log/vieux-logs/mrnet.log.1.gz ]];then
       i=1
         let i++
           mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.$i.gz
           else
      echo "theres no mrnet.log.1.gz in vieux-logs "
   fi 

its stops at mrnet.log.2.gz

how does it not make it that it doesn't become i becomes 1 everytime

OK. First: Please use CODE tags when submitting code and please use indentation that shows the structure of your code. For example, with code tags and indentation to show grouping, your sample code is:

if [ $(stat --printf="%s" /var/log/mrnet.log ) -gt 5000 ]
then    echo "mrnet greater 5000"
        gzip /var/log/mrnet.log
        mv /var/log/mrnet.log.gz /var/log/mrnet.log.1.gz
        if [[ -e /var/log/vieux-logs/mrnet.log.1.gz ]]
        then    i=1
                let i++
                mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.$i.gz
        else    echo "theres no mrnet.log.1.gz in vieux-logs "
        fi

which immediately shows that you are missing a closing fi at the end of your script.

Then, if we look at where i is set an used we see that the first reference sets i to 1 ( i=1 ) and on the next line i is incremented ( let i++ ) which sets i to 2. And then the next line uses i in the name of a file ( /var/log/vieux-logs/mrnet.log.$i.gz ). Since there aren't any other reference to i in the rest of your script and none of the logic in your script affects the way i is set or used, the three lines in your script:

i=1
let i++
mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.$i.gz

are logically equivalent to:

mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.2.gz
1 Like