I need to compare the size of the file generated today with the one of yesterday
Instead of constructing the filename for yesterday's file from today's date (which is tricky, as you found out), why not simply look for a file with the correct name (pattern) and a modification time of yesterday? That's much easier:
TODAYSSIZE=`find . -name "file*\.log" -daystart -mtime 0 -printf "%s"`
YESTERSIZE=`find . -name "file*\.log" -daystart -mtime 1 -printf "%s"`
Then do with the values whatever you need to do.
Tweak search path (.
), file name pattern (file*\.log
) and the actual size format displayed (%s
) to your requirements.
This is assuming you have GNU find
available; the find
shipped with AIX doesn't do -printf
. You can still use it to get the filenames, though:
TODAYSFILE=`find . -name "file*\.log" -daystart -mtime 0`
YESTERFILE=`find . -name "file*\.log" -daystart -mtime 1`
Then retrieve the file size any way you like (ls -s $TODAYSFILE
or whatever).
Note that find
works recursively, i.e. it would find logfiles in subdirectories as well. GNU find
can be told to -maxdepth 1
to avoid this, AIX find
cannot.