Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trimming nohup.out files periodically 1

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
US
Good Day,

We end up having large nohup.out files in multiple places. Is there a way to dynamically (without stopping the services) trim these files?

Regards,
Dan
 
If you want any of the data copy the file to somewhere else.

on the original file:

> nohup.out

this will clear out the file and leave the original file handles in place, so the original service will still append to it.
 
Thank you but the file seems to be locked...

Regards,
Dan
 
If logrotate doesn't work for you, you can do this. Don't use the default nohup.out and you should be ok.

First create a little script called "logger" that looks like this.

Code:
#!/bin/ksh

unset IFS

while read LINE
do
        LOGFILE=${1:-logfile}.$(date '+%Y%m%d').log
        print "${LINE}" >> ${LOGFILE}
done

Then, run your command like this...

Code:
nohup  myscript.sh  2>%1  |  ./logger  myscript  &

This will run your script (or program, or whatever) in the background, and the little "logger" script will automatically roll the log into a new file each day. The first parameter to "logger" will be the name of the log file. It will have the date (YYYYMMDD) and ".log" appended to it (example "myscript.20121231.log"). Changing the date format will change how often the log is "rolled".




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top