I am running a command with nohup on one of my servers, the output file has become too big and I predict that the process would need an extra month of execution before it completes. Is there a way to change the nohup output file while the process is running?
The idea given in one of the comments is generally what's done, even if the link to another question has an erroneous (and unaccepted) answer.
To truncate the file in a POSIX shell use:
cat /dev/null > _name_of_file_
cp as one answer in the link suggests. Of course, you might want to copy the old file to a different filesystem or to a remote location if you want to save it first.
In low-level terms, the difference is that you are opening the existing file and with its inode and truncating it. See http://man7.org/linux/man-pages/man2/open.2.html and the
Some other things that work in special cases. I sometimes check
/etc/logrotate.d (or some other suitable log rotation program) to see how that swaps out files. Some commands like apache2 have a
reload command that cause it to load a configuration file and in the process reopen log files.
Just found this neat little utility that enabled me to redirect the output to another file and everything is working fine now. The utility is called reredirect and can be found in: https://github.com/jerome-pouiller/reredirect/
A simple command like:
reredirect -m FILE PID gets the job done.