1748106 Members
4852 Online
108758 Solutions
New Discussion юеВ

Re: Log rotation daily

 
Fenglin
Regular Advisor

Log rotation daily

Hi

I would like to do a daily log rotation for the script attached. Anyone can help ?

Regards
Feng Lin
7 REPLIES 7
R.K. #
Honored Contributor

Re: Log rotation daily

HI Fenglin,

We can use cron.
# crontab -e
Don't fix what ain't broke
Fenglin
Regular Advisor

Re: Log rotation daily

Sorry

The current script just run a single file and keeps appending to the same file daily.

It is not producing a daily file itself. That is what I intend to do.

Regards
Feng Lin
R.K. #
Honored Contributor

Re: Log rotation daily

Hi Again,

log_file=log_`date +%Y%m%d%H%M`_readSMS.txt

So this says that everytime the script runs, it will produce a new file like log_200912022232_readSMS.txt.

So, if you do not want new file to be created, you should remove `date +%Y%m%d%H%M` above.
Don't fix what ain't broke
Fenglin
Regular Advisor

Re: Log rotation daily

Hi R K

The objective is, Once the script runs, it produces a daily logfile. The logfile logrotates every day with the timestamp. There is no interference manually. Currently, the file just keeps on appending to the file produced.

FYI,the process is meant to run 24*7.

Do you get what I mean?

Regards
Feng Lin
Yogeeraj_1
Honored Contributor

Re: Log rotation daily

hi,
You will have to restart the java process daily so that the line:

log_file=log_`date +%Y%m%d%H%M`_readSMS.txt

be effective.

otherwise, the system will continue logging to the same file as at the date/time it was launched.

If not feasible, you will have to write another script that backups the log file and truncates the current one.

hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Arturo Galbiati
Esteemed Contributor

Re: Log rotation daily

Viktor Balogh
Honored Contributor

Re: Log rotation daily

you could define an OUTFILE variable like this:

OUTFILE=/path/to/logs/log_$(date +%Y%m%d%H%M)

after that run your app like this:

if [ "$my_process" = "" ]
then
nohup java $JAVA_JVM -Xms128m \
-Xmx128m -verbose:gc -XX:PermSize=64m \
-XX:MaxPermSize=64m -XX:SurvivorRatio=6 \
com.nsp.sms.batch.ReadSMSBatch \
1>> ${OUTFILE} 2>> ${OUTFILE} &
fi

...but you need to start it over every day to refresh the value of the variable $OUTFILE
****
Unix operates with beer.