Hello,
I have a command which runs continuously and creates output to STDOUT. Now, in unix, if I create logging for this command, it would create a single log file and keep on updating. As there is so much data filled in it, I would want to break the log files periodically. In this instance, say if I want to break the log files every hour, how can I do that?
Thanks in advance!
you can rename the logfile every hour by adding time stamp to the name of file . as per your requirement define the $time variable using date command. cron can be used to schedule it every hr.
ex - mv system.log system.log.$time
thanks for the information!
I was able to proceed as you mentioned.
hello,
i was able to do it but then i do not want to run the process/restart the process every hour.
if i start the process now, let it run for the whole day and I would like to create hourly logs without restarting.
is there a way?
Try this...
#!/bin/bash
#logger.sh script
log_file=/tmp/process.log
tmp_log_file=/tmp/process.log.$$
while true
do
sleep 3600
cp $log_file $tmp_log_file
>$log_file
mv $tmp_log_file $log_file.$(date +%d%m%Y_%H%M)
done
If interested, you can cron this script to be executed every one hour...
--ahamed