{"id":4420,"date":"2017-03-09T16:03:02","date_gmt":"2017-03-09T16:03:02","guid":{"rendered":"http:\/\/hostileblog.com\/?p=4420"},"modified":"2020-05-30T21:35:30","modified_gmt":"2020-05-31T01:35:30","slug":"fix-logrotate-not-working-problem","status":"publish","type":"post","link":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/","title":{"rendered":"How to fix logrotate not working problem?"},"content":{"rendered":"\n

If your app<\/span> is appending the errors and website visitor’s IP address, browser data, etc to a log<\/span> file, you should manually archive<\/span> old log<\/span> files or use Logrotate.<\/p>\n\n\n\n

If you don’t do so, the server<\/span> will run out of storage memory<\/a> and your application<\/span> may crash.<\/p>\n\n\n\n

Logrotate is a powerful program<\/span> that archives and removes old log<\/span> files. It saves heaps of storage memory by automatically compressing log<\/span> files generated by Apache<\/span>, NGINX, MySQL<\/span>, etc.<\/p>\n\n\n\n

The tool has two main modules, a script<\/span> that executes the task<\/span> of rotating logs<\/span> and a configuration file.<\/p>\n\n\n\n

When you install and start the web or a database server<\/a>, Logrotate creates a configuration file for the same in the Logrotate directory.<\/p>\n\n\n\n

For example, If you have installed and started Apache<\/span> web server<\/span>, Logrotate will create apache config file.<\/p>\n\n\n\n

Unless you make changes to the config file, the tool will rotate log<\/span> files saved in the \/var\/log<\/span> directory.<\/p>\n\n\n\n

By default, the script<\/span> that runs the task of rotating logs is saved in the cron.daily folder which means that the script<\/span> is executed once in a day.<\/p>\n\n\n\n

Logrotate not working error<\/h2>\n\n\n\n

Yesterday, I made some changes to the Anacron<\/a> configuration file and changed the value<\/span> of variable<\/span> START_HOURS_RANGE of the Anacrontab.<\/p>\n\n\n\n

\"logrotate<\/figure><\/div>\n\n\n\n

On some systems, the Anacron program<\/span> executes the Cron, hour, daily, and weekly scripts<\/span> instead of the crontab.<\/p>\n\n\n\n

Anacron’s executable file is stored in the bin directory and configuration file is saved to the etc directory.<\/p>\n\n\n\n

I \u00a0had to make changes to the Anacrontab file because I had changed the timezone on my VPS<\/a> to IST. But, the log files<\/a> were generated on UTC time. Furthermore, the crontab file was empty.<\/p>\n\n\n\n

I saved the changes and waited for Logrotate to rotate logs. Unfortunately, the program<\/span> failed to work.<\/p>\n\n\n\n

Anacron was executing hourly Cron jobs. But for some reasons, it wasn’t running the daily task<\/span>.<\/p>\n\n\n\n

To fix the problem, I moved the script<\/span> to some other folder on the system. Then, I configured<\/span> crontab to execute it.<\/p>\n\n\n\n

Example: Crontab file’s content<\/p>\n\n\n\n

13 13 * * * \/dir1\/logrotate.sh<\/code><\/p>\n\n\n\n

The above line in the crontab file ensures that the Logrotate\u00a0script<\/a> saved in the dir1 directory is executed daily at 13:13 local time.<\/p>\n\n\n\n

You can modify the above line as per your requirements.<\/p>\n\n\n\n

Follow the below steps to create a cronjob for Logrotate<\/p>\n\n\n\n

1) Open the terminal, type the\u00a0crontab -e command and press enter.<\/p>\n\n\n\n

2)\u00a0Add the cronjob, save the file and close the editor.<\/p>\n\n\n\n

3) Restart crond service<\/span><\/p>\n\n\n\n

Now, the script will work as per your expectations.<\/p>\n\n\n\n

If the above solution doesn’t work for you, make sure that the shell script and config files are error free.<\/p>\n","protected":false},"excerpt":{"rendered":"

If your app is appending the errors and website visitor’s IP address, browser data, etc to a log file, you should manually archive old log files or use Logrotate. If you don’t do so, the server will run out of storage memory and your application may crash. Logrotate is a powerful program that archives and […]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[11413,7003,7033,7036,7038],"post_series":[],"yoast_head":"\nHow to fix logrotate not working problem? - Ian Carnaghan<\/title>\n<meta name=\"description\" content=\"Learn how to fix Logrotate not working error here. Logrotate saves heaps of storage memory by automatically compressing log files generated ...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to fix logrotate not working problem? - Ian Carnaghan\" \/>\n<meta property=\"og:description\" content=\"Learn how to fix Logrotate not working error here. Logrotate saves heaps of storage memory by automatically compressing log files generated ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\" \/>\n<meta property=\"og:site_name\" content=\"Ian Carnaghan\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-09T16:03:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-31T01:35:30+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg\" \/>\n<meta name=\"author\" content=\"Pramod\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@icarnaghan\" \/>\n<meta name=\"twitter:site\" content=\"@icarnaghan\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pramod\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\"},\"author\":{\"name\":\"Pramod\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb\"},\"headline\":\"How to fix logrotate not working problem?\",\"datePublished\":\"2017-03-09T16:03:02+00:00\",\"dateModified\":\"2020-05-31T01:35:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\"},\"wordCount\":445,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\"},\"image\":{\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg\",\"keywords\":[\"Affiliate\",\"Apache\",\"Logs\",\"MySQL\",\"Nginx\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\",\"url\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\",\"name\":\"How to fix logrotate not working problem? - Ian Carnaghan\",\"isPartOf\":{\"@id\":\"https:\/\/www.carnaghan.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg\",\"datePublished\":\"2017-03-09T16:03:02+00:00\",\"dateModified\":\"2020-05-31T01:35:30+00:00\",\"description\":\"Learn how to fix Logrotate not working error here. Logrotate saves heaps of storage memory by automatically compressing log files generated ...\",\"breadcrumb\":{\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage\",\"url\":\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg\",\"contentUrl\":\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.carnaghan.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to fix logrotate not working problem?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.carnaghan.com\/#website\",\"url\":\"https:\/\/www.carnaghan.com\/\",\"name\":\"Ian Carnaghan\",\"description\":\"Software Developer, Blogger, Educator\",\"publisher\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.carnaghan.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\",\"name\":\"Ian Carnaghan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g\",\"caption\":\"Ian Carnaghan\"},\"logo\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\"},\"description\":\"I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.\",\"sameAs\":[\"http:\/\/www.carnaghan.com\",\"https:\/\/x.com\/icarnaghan\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb\",\"name\":\"Pramod\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g\",\"caption\":\"Pramod\"},\"description\":\"My name is Pramod. I\u2019m a software developer (with good knowledge on PHP, JAVA \u2013 Android, JavaScript, CSS), blogger and online marketing professional. I\u2019ve 3 years of experience as a blogger and 2 years of full time experience as a software developer.\",\"url\":\"https:\/\/www.carnaghan.com\/author\/prhost78\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to fix logrotate not working problem? - Ian Carnaghan","description":"Learn how to fix Logrotate not working error here. Logrotate saves heaps of storage memory by automatically compressing log files generated ...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/","og_locale":"en_US","og_type":"article","og_title":"How to fix logrotate not working problem? - Ian Carnaghan","og_description":"Learn how to fix Logrotate not working error here. Logrotate saves heaps of storage memory by automatically compressing log files generated ...","og_url":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/","og_site_name":"Ian Carnaghan","article_published_time":"2017-03-09T16:03:02+00:00","article_modified_time":"2020-05-31T01:35:30+00:00","og_image":[{"url":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg"}],"author":"Pramod","twitter_card":"summary_large_image","twitter_creator":"@icarnaghan","twitter_site":"@icarnaghan","twitter_misc":{"Written by":"Pramod","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#article","isPartOf":{"@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/"},"author":{"name":"Pramod","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb"},"headline":"How to fix logrotate not working problem?","datePublished":"2017-03-09T16:03:02+00:00","dateModified":"2020-05-31T01:35:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/"},"wordCount":445,"commentCount":0,"publisher":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5"},"image":{"@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage"},"thumbnailUrl":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg","keywords":["Affiliate","Apache","Logs","MySQL","Nginx"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/","url":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/","name":"How to fix logrotate not working problem? - Ian Carnaghan","isPartOf":{"@id":"https:\/\/www.carnaghan.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage"},"image":{"@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage"},"thumbnailUrl":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg","datePublished":"2017-03-09T16:03:02+00:00","dateModified":"2020-05-31T01:35:30+00:00","description":"Learn how to fix Logrotate not working error here. Logrotate saves heaps of storage memory by automatically compressing log files generated ...","breadcrumb":{"@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#primaryimage","url":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg","contentUrl":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2017\/03\/logrotate-1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.carnaghan.com\/fix-logrotate-not-working-problem\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.carnaghan.com\/"},{"@type":"ListItem","position":2,"name":"How to fix logrotate not working problem?"}]},{"@type":"WebSite","@id":"https:\/\/www.carnaghan.com\/#website","url":"https:\/\/www.carnaghan.com\/","name":"Ian Carnaghan","description":"Software Developer, Blogger, Educator","publisher":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.carnaghan.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5","name":"Ian Carnaghan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g","caption":"Ian Carnaghan"},"logo":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/"},"description":"I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.","sameAs":["http:\/\/www.carnaghan.com","https:\/\/x.com\/icarnaghan"]},{"@type":"Person","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb","name":"Pramod","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g","caption":"Pramod"},"description":"My name is Pramod. I\u2019m a software developer (with good knowledge on PHP, JAVA \u2013 Android, JavaScript, CSS), blogger and online marketing professional. I\u2019ve 3 years of experience as a blogger and 2 years of full time experience as a software developer.","url":"https:\/\/www.carnaghan.com\/author\/prhost78\/"}]}},"views":1969,"_links":{"self":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/posts\/4420"}],"collection":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/comments?post=4420"}],"version-history":[{"count":0,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/posts\/4420\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/media?parent=4420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/categories?post=4420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/tags?post=4420"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/post_series?post=4420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}