1

For some reason when I run this it is not seeing $(stat -c %s ./dropcache.log) as a value, but as a command when trying to assign the result to variable file_size on line 6. Does anyone know why that might be?

#!
MAXLOGS=4
while true
do
MAXFILESIZE=10000
  file_size= $(stat -c %s ./dropcache.log)
  if [ $file_size -gt $MAXFILESIZE ];
  then
    if [ -f dropcachelog.$MAXLOGS ]
    then 
      rm dropcachelog.$MAXLOGS
    fi
    NUM=$(($MAXLOGS - 1))
    while [ $NUM -ge 0 ]
      do
      NUM1=$(($NUM + 1))
      if [ -f dropcache.$NUM ]; 
        then mv dropcache.$NUM dropcache.$NUM1
      fi

      done
          if [ -f dropcache.log ];
        then mv dropcache.log dropcache.0
        touch dropcache.log
      fi  
fi

      
    
  free >  stats
  u=$(awk 'NR == 2 {print $6}' stats)
  if [ $u -gt 200000 ]
  then  
    (date +%Y/%m/%d--%H:%M.%S)» dropcache.log
    (awk 'NR == 2 {print $6}' stats)  » dropcache.log
    sudo echo  "1" >   /proc/sys/vm/drop_caches
  fi
done

0 Answers0