Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit size of nohup.out logs

Tags:

nohup

I use the command:

nohup <command to run> & 

and it logs to the nohup.out file, however this log file could get pretty BIG so was wondering if there was a way to automatically save off the output to nohup1.out, nohup2.out nohup3.out etc when the nohup.out gets too big. This is all without terminating the original command.

like image 968
k.nguyen Avatar asked Dec 07 '15 17:12

k.nguyen


1 Answers

logrotate(8) is likely what you need and probably already in your Linux distro. Specify in /etc/logrotate.conf the size limit and how many rotations you want:

From an example on thegeekstuff.com:

/tmp/output.log {
        size 1k
        create 700 user user
        rotate 4
}
  • size 1k – logrotate runs only if the filesize is equal to (or greater than) this size.
  • create – rotate the original file and create the new file with specified permission, user and group.
  • rotate – limits the number of log file rotation. So, this would keep only the recent 4 rotated log files.

Then run logrotate /etc/logrotate.conf

I ignored the example's file status location since logrotate is already running as a cron job by my system and a status file already exists (in a different location from the example's).

like image 171
fenwick Avatar answered Sep 22 '22 08:09

fenwick