{"id":665,"date":"2010-02-28T13:04:41","date_gmt":"2010-02-28T18:04:41","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=665"},"modified":"2011-07-06T10:35:26","modified_gmt":"2011-07-06T15:35:26","slug":"logrotate-configured-by-mere-mortals","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2010\/02\/28\/logrotate-configured-by-mere-mortals\/","title":{"rendered":"logrotate configured by mere mortals"},"content":{"rendered":"<p>This will provide a way to implement log file rotations by a non-privileged users using the standard Linux logrotate infrastructure.<\/p>\n<p>For our test case, we set up a log file that looks similar to a &#8220;normal&#8221; log file we may want to periodically roll over.<\/p>\n<pre lang=\"text\" line=\"1\">\r\nhowards@howards:~$ i=1\r\nhowards@howards:~$ while [ $i -le 100 ]; do echo $(date) $i iteration >> my.log; i=$(($i + 1)); done\r\nhowards@howards:~$ tail -5 my.log\r\nSun Feb 28 11:49:41 EST 2010 96 iteration\r\nSun Feb 28 11:49:41 EST 2010 97 iteration\r\nSun Feb 28 11:49:41 EST 2010 98 iteration\r\nSun Feb 28 11:49:41 EST 2010 99 iteration\r\nSun Feb 28 11:49:41 EST 2010 100 iteration\r\nhowards@howards:~$\r\n<\/pre>\n<p>To archive this log and create a new empty version for ongoing activity, we need a logrotate.conf file in a user accessible location with read\/write permissions.<\/p>\n<p>I put mine under \/home\/howards, with the contents below&#8230;<\/p>\n<pre lang=\"text\" line=\"1\">\r\n\/home\/howards\/my.log {\r\nmissingok\r\ndaily\r\ncompress\r\ndelaycompress\r\ncreate 0644 howards howards\r\nrotate 7\r\n}\r\n<\/pre>\n<p>RTFM for the meaning of each parameter above, but they are probably self explanatory, anyway.<\/p>\n<p>We can then begin running our logrotate as shown below.  Keep in mind the following two things:<\/p>\n<ul>\n<li>the &#8211;force parameter is not necessary except for when testing.<\/li>\n<li>the &#8211;state parameter is necessary as non-privileged users will not be able to write to the default location<br \/>\nof \/var\/lib\/logrotate\/status<\/li>\n<\/ul>\n<pre lang=\"text\" line=\"1\">\r\nhowards@howards:~$ ls -lrt my.log*\r\n-rw-r--r-- 1 howards howards 4192 2010-02-28 11:52 my.log\r\nhowards@howards:~$ logrotate --force logrotate.conf --state=mystate\r\nhowards@howards:~$ ls -lrt my.log*\r\n-rw-r--r-- 1 howards howards 4192 2010-02-28 11:52 my.log.1\r\n-rw-r--r-- 1 howards howards    0 2010-02-28 11:52 my.log\r\nhowards@howards:~$ i=1\r\nhowards@howards:~$ while [ $i -le 100 ]; do echo $(date) $i iteration &gt;&gt; my.log; i=$(($i + 1)); done\r\nhowards@howards:~$ logrotate --force logrotate.conf --state=mystate\r\nhowards@howards:~$ ls -lrt my.log*\r\n-rw-r--r-- 1 howards howards  316 2010-02-28 11:52 my.log.2.gz\r\n-rw-r--r-- 1 howards howards 4192 2010-02-28 11:52 my.log.1\r\n-rw-r--r-- 1 howards howards    0 2010-02-28 11:52 my.log\r\nhowards@howards:~$\r\n<\/pre>\n<p>Put something similar to the following line in your user crontab, and you should be good to go.<\/p>\n<pre lang=\"text\" line=\"1\">\r\n0 0 * * * \/usr\/sbin\/logrotate \/home\/howards\/logrotate.conf --state=\/home\/howards\/mystate\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This will provide a way to implement log file rotations by a non-privileged users using the standard Linux logrotate infrastructure. For our test case, we set up a log file that looks similar to a &#8220;normal&#8221; log file we may&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2010\/02\/28\/logrotate-configured-by-mere-mortals\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[28,27],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/665"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=665"}],"version-history":[{"count":9,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/665\/revisions"}],"predecessor-version":[{"id":1377,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/665\/revisions\/1377"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=665"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}