{"id":266,"date":"2017-03-21T10:51:30","date_gmt":"2017-03-21T09:51:30","guid":{"rendered":"http:\/\/eppesuigoccas.homedns.org\/wordpress\/?p=266"},"modified":"2017-03-21T11:26:40","modified_gmt":"2017-03-21T10:26:40","slug":"logrotate-e-postrotate","status":"publish","type":"post","link":"https:\/\/blog.sguazz.it\/index.php\/archives\/266","title":{"rendered":"logrotate e postrotate"},"content":{"rendered":"<p>Il logrotate \u00e8 un strumento molto utile che gestisce i file di log delle varie applicazioni. Ogni giorno viene eseguito dal cron e, in base alla configurazione, archivia tutti i log. Tra le cose interessanti c&#8217;\u00e8 la possibilit\u00e0 di eseguire un comando dopo l&#8217;archiviazione del log (e prima della sua eventuale compressione). L&#8217;operazione che viene eseguita normalmente a fine archiviazione, \u00e8 quella di avvisare l&#8217;applicazione di utilizzare un nuovo file di log.<br \/>\nAd esempio, nel file \/etc\/logrotate.d\/rsyslog di Debian c&#8217;\u00e8 scritto:<\/p>\n<pre>postrotate\r\ninvoke-rc.d rsyslog rotate &gt; \/dev\/null\r\nendscript<\/pre>\n<p>oppure, nel file \/etc\/logrotate.d\/apache2 c&#8217;\u00e8 scritto:<\/p>\n<pre>postrotate\r\nif \/etc\/init.d\/apache2 status &gt; \/dev\/null ; then \\\r\n\/etc\/init.d\/apache2 reload &gt; \/dev\/null; \\\r\nfi;\r\nendscript<\/pre>\n<p>Il manuale, a proposito del postrotate, dice:<br \/>\n<em>The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed (using \/bin\/sh) after the log file is rotated. These directives may only appear inside a log file definition. Normally, the absolute path to the log file is passed as first argument to the\u00a0 script. If\u00a0 sharedscripts is specified, whole pattern is passed to the script. See also prerotate. See sharedscripts and nosharedscripts for error handling.<\/em><\/p>\n<p>Il secondo esempio dovrebbe fare scattare un campanello d&#8217;allarme riguardo la sintassi da usare nel postrotate: non si tratta di uno script composto da vari comandi, ma di linee che vengono eseguite tramite la shell. Allora, se il comando \u00e8 uno solo, come nel caso di rsyslog, non c&#8217;\u00e8 problema, ma se si usano varie linee, \u00e8 <strong>necessario<\/strong> concatenarle tramite il <em>backslash<\/em> a fine riga, e utilizzare <strong>sempre<\/strong> il separatore \u00ab;\u00bb tra i comandi.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Il logrotate \u00e8 un strumento molto utile che gestisce i file di log delle varie applicazioni. Ogni giorno viene eseguito dal cron e, in base alla configurazione, archivia tutti i log. Tra le cose interessanti c&#8217;\u00e8 la possibilit\u00e0 di eseguire un comando dopo l&#8217;archiviazione del log (e prima della sua eventuale compressione). L&#8217;operazione che viene [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[4,3,11,10],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-aside","hentry","category-sysadmin","category-computer","category-debian","category-open-source","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/comments?post=266"}],"version-history":[{"count":2,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":268,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/posts\/266\/revisions\/268"}],"wp:attachment":[{"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/media?parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/categories?post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sguazz.it\/index.php\/wp-json\/wp\/v2\/tags?post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}