I have a bash script which always giving output where I have it redirected to a file, what i'm trying to do is to rotate the redirected file, below is where i start the original script and redirect it:
.
somecode
.
su - username -c "command >> /path/to/directory/output.txt" &
.
.
code continues..
and below is the crontab i'm trying to create:
cd /path/to/directory/
timestamp=`date "+%Y%m%d"`
mv ./output.txt ./logs/output.txt_$timestamp
touch output.txt
chmod 757 ./output.txt
gzip ./logs/output.txt_$timestamp
find ./logs/output.txt* -type f -mtime +2 | xargs rm
or this one also failed to do the job:
timestamp=`date "+%Y%m%d"`
cp ./output.txt ./logs/output.txt_$timestamp
echo "" > ./output.txt
gzip ./logs/output.txt_$timestamp
in the first code the original script fails and is no longer working, and in the second script it doesn't clean the output.txt file.
Is there a way to do it while keeping the script working ? Note; i'm running Unix Solaris.
Thanks in advance.