How to know a file is of fixed file or not over a span of time Actually my requirement is to check the size of the file in a specific directory for 60 seconds, and if it remains the same then I have to move to some other directory.Else I have to stop the execution. Request you to guide me in knowing the varying size of the file.
I got to know to calculate the file size with the following code:
filesize=`ls -l output.txt |awk '{print $5 }'`
echo $filesize
how to check it for 60 seconds?.
Thanks.,
sample
filesize=`ls -l output.txt |awk '{print $5 }'`
echo $filesize
sleep 60
filesize_2=`ls -l output.txt |awk '{print $5 }'`
if [ $filesize != $filesize_2 ]
then
echo "not equal, it has changed"
fi
1 Like
use while loop
filesize=`ls -l output.txt |awk '{print $5 }'`
cnt=1
echo $filesize
while [1]
do
filesize_new=`ls -l output.txt |awk '{print $5 }'`
if [ $filesize -ne $filesize_new ]
echo "exiting the script"
exit 10
fi
if [ $cnt -eq 2 ]; then
mv output.txt sometoehlocation/output.txt
else
sleep 60
cnt=$(( cnt + 1 ))
fi
exit 0
done
cheers,
Devaraj Takhellambam
1 Like
av_vinay:
How to know a file is of fixed file or not over a span of time Actually my requirement is to check the size of the file in a specific directory for 60 seconds, and if it remains the same then I have to move to some other directory.Else I have to stop the execution. Request you to guide me in knowing the varying size of the file.
I got to know to calculate the file size with the following code:
filesize=`ls -l output.txt |awk '{print $5 }'`
echo $filesize
how to check it for 60 seconds?.
Thanks.,
You can use something like following :
# S=`ls -l b |awk '{print $5 }'`;P=0
# while [ $P -lt 60 ]
do
size=`ls -l b |awk '{print $5 }'`
echo $size
if [[ "$size" -ne "$S" ]];then
echo "Size has changed... Hence moving the file..."
mv first_location final_location
break
else
sleep 1
fi
P=`expr $P + 1`
S="$size"
done
1 Like
Thanks guys. The script is working fine:b: