Monday, January 17, 2011

rotate nohup out file (nohup.log)

I got this article by posting on serverfault.com on how to rotate the nohup log file.
Basically you connect the output of nohup to a pipe that is redirecting to a file - then the file can me moved around very easily.

mknod /tmp/mypipe p
cat < /tmp/mypipe >/tmp/myreallog
nohup myapplication >/tmp/mypipe


To rotate the log:
mv /tmp/myreallog /tmp/rotatedlog
kill [pid of the cat process]
cat < /tmp/mypipe >/tmp/myreallog


2 comments:

Rob said...

This was great. I was able to incorporate the concept to rotate nohup logs growing quickly from FD exhaustion.

Anonymous said...

Just before you do your nohup call, just add :

cat < /tmp/mypipe > /dev/null &

With this addition, the nohup will survive if the other "cat" process is killed, if the nohup task writes to it before the "cat" process is recreated.