<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Aldolat.it &#8212; Post con tag Monitoraggio</title>
        <link>https://www.aldolat.it/tags/monitoraggio/</link>
        <description>Ultimi post pubblicati nel tag Monitoraggio &#8212; aldolat.it</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>it</language>
        <managingEditor>aldolat@gmail.com (Aldo Latino)</managingEditor>
        <webMaster>aldolat@gmail.com (Aldo Latino)</webMaster>
        <copyright>Creative Commons BY-SA 4.0</copyright>
        <lastBuildDate>Fri, 18 Apr 2025 23:25:50 +0200</lastBuildDate>
        <atom:link href="https://www.aldolat.it/tags/monitoraggio/index.xml" rel="self" type="application/rss+xml" />
        <item>
            <title>Monitorare i cambiamenti in una directory in Linux</title>
            <link>https://www.aldolat.it/posts/2025/monitorare-cambiamenti-directory-linux/</link>
            <pubDate>Sat, 15 Mar 2025 07:54:00 +0100</pubDate>
            <author>aldolat@gmail.com (Aldo Latino)</author>
            <guid>https://www.aldolat.it/posts/2025/monitorare-cambiamenti-directory-linux/</guid>
            <description>Recentemente mi è capitato di dover tenere sotto controllo le modifiche fatte in una directory nella mia home. Per questo scopo mi sono servito di inotifywait presente nel pacchetto inotify-tools. Questo programma restituisce proprio le informazioni che mi servivano, ad esempio:&#xA;/path/to/dir/.git/objects/info/ CREATE commit-graph.lock /path/to/dir/.git/objects/info/ MODIFY commit-graph.lock /path/to/dir/.git/ DELETE gc.pid /path/to/dir/.git/ CREATE index.lock /path/to/dir/.git/ DELETE index.lock /path/to/dir/.git/refs/remotes/origin/ CREATE master.lock /path/to/dir/.git/refs/remotes/origin/ MODIFY master.lock /path/to/dir/.git/logs/refs/remotes/origin/ MODIFY master La directory sotto controllo era /path/to/dir/, comprese le sue sotto directory, e &amp;mdash; com&amp;rsquo;è evidente &amp;mdash; su ogni riga il programma mostra in sequenza:</description>
            <content:encoded>&lt;p class=&#34;dc&#34;&gt;R&lt;span class=&#34;allsc&#34;&gt;ecentemente&lt;/span&gt; mi è capitato di dover tenere sotto&#xA;controllo le modifiche fatte in una directory nella mia home. Per questo scopo&#xA;mi sono servito di &lt;code&gt;inotifywait&lt;/code&gt; presente nel pacchetto &lt;code&gt;inotify-tools&lt;/code&gt;. Questo&#xA;programma restituisce proprio le informazioni che mi servivano, ad esempio:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/objects/info/ CREATE commit-graph.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/objects/info/ MODIFY commit-graph.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/ DELETE gc.pid&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/ CREATE index.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/ DELETE index.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/refs/remotes/origin/ CREATE master.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/refs/remotes/origin/ MODIFY master.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/path/to/dir/.git/logs/refs/remotes/origin/ MODIFY master&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;La directory sotto controllo era &lt;code&gt;/path/to/dir/&lt;/code&gt;, comprese le sue sotto&#xA;directory, e &amp;mdash; com&amp;rsquo;è evidente &amp;mdash; su ogni riga il programma mostra in&#xA;sequenza:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;la directory dov&amp;rsquo;è avvenuta la modifica;&lt;/li&gt;&#xA;&lt;li&gt;l&amp;rsquo;azione eseguita;&lt;/li&gt;&#xA;&lt;li&gt;il file interessato.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;installazione&#34;&gt;Installazione&lt;/h2&gt;&#xA;&lt;p&gt;Installiamo anzitutto il pacchetto &lt;code&gt;inotify-tools&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;sudo pacman -Syu inotify-tools&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;esecuzione&#34;&gt;Esecuzione&lt;/h2&gt;&#xA;&lt;p&gt;Eseguiamo &lt;code&gt;inotifywait&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;inotifywait -m -r -e modify,create,delete /percorso/alla/directory&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Le opzioni fornite significano:&lt;/p&gt;&#xA;&lt;dl&gt;&#xA;&lt;dt&gt;&lt;code&gt;-m&lt;/code&gt; (o anche &lt;code&gt;--monitor&lt;/code&gt;)&lt;/dt&gt;&#xA;&lt;dd&gt;Rimane in ascolto delle modifiche;&lt;/dd&gt;&#xA;&lt;dt&gt;&lt;code&gt;-r&lt;/code&gt; (o anche &lt;code&gt;--recursive&lt;/code&gt;)&lt;/dt&gt;&#xA;&lt;dd&gt;Controlla anche le sotto directory;&lt;/dd&gt;&#xA;&lt;dt&gt;&lt;code&gt;-e&lt;/code&gt; (o anche &lt;code&gt;--event&lt;/code&gt;)&lt;/dt&gt;&#xA;&lt;dd&gt;Controlla quali eventi deve monitorare. Se non specificato, controlla tutti&#xA;gli eventi.&lt;/dd&gt;&#xA;&lt;/dl&gt;&#xA;&lt;p&gt;Nel manuale di &lt;code&gt;inotifywait&lt;/code&gt; possiamo vedere quali siano gli eventi disponibili&#xA;per il monitoraggio:&lt;/p&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Evento&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Descrizione&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;access&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory contents were read&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;attrib&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory attributes changed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;close&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory closed, regardless of read/write mode&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;close_nowrite&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory closed, after being opened in read-only mode&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;close_write&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory closed, after being opened in writable mode&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;create&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory created within watched directory&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;delete&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory deleted within watched directory&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;delete_self&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory was deleted&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;modify&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory contents were written&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;move&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory moved to or from watched directory&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;moved_from&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory moved from watched directory&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;moved_to&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory moved to watched directory&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;move_self&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;A watched file or directory was moved.&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;open&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file or directory opened&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;code&gt;unmount&lt;/code&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;file system containing file or directory unmounted&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p class=&#34;table-caption&#34;&gt;&lt;span class=&#34;sc&#34;&gt;Tabella 1&lt;/span&gt;. Gli eventi disponibili in &lt;code&gt;inotifywait&lt;/code&gt; per il monitoraggio.&lt;/p&gt;&#xA;&lt;p&gt;L&#39;articolo &lt;a href=&#34;https://www.aldolat.it/posts/2025/monitorare-cambiamenti-directory-linux/&#34;&gt;Monitorare i cambiamenti in una directory in Linux&lt;/a&gt; è uno scritto di &lt;a href=&#34;https://www.aldolat.it/&#34;&gt;aldolat.it&lt;/a&gt;. Rispettane le &lt;a href=&#34;https://www.aldolat.it/info/#licenza&#34;&gt;condizioni di licenza&lt;/a&gt;.&lt;/p&gt;</content:encoded>
        </item>
    </channel>
</rss>
