shell script to convert file_size from bytes to megabytes

Hi All,

OS:AIX 64 bits.

Requirement is to convert file_size from bytes to megabytes through shell script as below:

export DBALIST="xyz@rediffmail.com"

ls -ltr abcd.txt > file_size.result
export file_size=`awk -F" " '{ print $5 }' file_size.result`
if [[ $file_size > 104857 ]]
then
mailx -s "File abcd.txt is ${file_size}/1024/1024 full" $DBALIST < file_size.result
#rm file_size.result
fi

But getting syntax errors while converting using eval or expr.

Thanks for your time!

Please use the proper tags to make the entry more readable. I took out the email code, you can do with it as you will.

How about:

ls -ltr abcd.txt > file_size.result
export file_size=`awk -F" " '{ print $5 }' file_size.result`
if [[ $file_size > 104857 ]]
then
  echo "File abcd.txt is `echo ${file_size}/1024/1024 | bc` full"
fi

Hi Peterro,

Thanks a lot for your time!It worked!

Great!

Regards,

You could also do $((file_size >> 20)) instead of /1024/1024.