unix - Keep log file of shell script execution until past few days -
am appending standard output , error of shell script execution on unix bok shown below
/home/mydir/shellscript.sh >> /home/mydir/shellscript.log 2>&1
now wondering way keep logs going as 30 days else log file size keep on increasing. appreciate if can provide recommendations around same.
is long-running script (e.g. daemon)? or exits quickly? dynamically build log file's name based on today's date, new file gets generated time date changes:
#/bin/sh now=`date +%f` /home/mydir/shellscript.sh >> /home/mydir/shellscript-$now.log 2>&1 previous=`date --date='30 days ago' +%f` rm -f /home/mydir/shellscript-$previous.log 2>&1
(added stale log removal).
Comments
Post a Comment