I have a 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 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.