Table of Contents
In this article, I will take you through the steps to install iwatch command on Ubuntu 20.04 LTS. iwatch is a free and open source Perl program which uses inotify to monitor changes in specific directories or files, sending alarms to the system administrator in real time. It can also be used within scripts and programs to take programmable actions immediately. iwatch can run as daemon as well as a simple command. One of the many cool features that it has is when it is used to monitor a directory, then it not only monitors that directory but also all the files inside that directory. It is one of the favorite System Monitoring tool used by the Linux and System Administrators.
How to Install iwatch command on Ubuntu 20.04 LTS
Also Read: How to Install Zikula CMS on Ubuntu 20.04 LTS [Step by Step]
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04 LTS
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
utility available in your System.
Step 2: Update Your Server
It is always a good idea to check for any latest available updates using apt-get update
command to keep your System packages up to date.
root@localhost:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [562 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,344 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [279 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [357 kB]
Get:9 http://in.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:10 http://in.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [10.4 kB]
Step 3: Install iwatch
iwatch package can be installed from Ubuntu repo along with all its dependencies using apt-get install iwatch -y
command as shown below. During the Installation, you need to first provide the type of mail configuration and then the FQDN information to send and receive the notifications through email. Here I am using Internet site
configuration to send and receive the mail using SMTP protocol and providing iwatch.example.com
as my FQDN. You can choose to use different configuration based on your needs.
root@localhost:~# apt-get install iwatch -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libauthen-sasl-perl libcommon-sense-perl libdata-dump-perl libevent-perl libfile-listing-perl libfont-afm-perl libhtml-form-perl libhtml-format-perl
libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-negotiate-perl libio-socket-ssl-perl liblinux-inotify2-perl liblwp-protocol-https-perl
libmail-sendmail-perl libmailtools-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libsys-hostname-long-perl libtry-tiny-perl libwww-perl
libwww-robotrules-perl libxml-libxml-perl libxml-namespacesupport-perl libxml-parser-perl libxml-sax-base-perl libxml-sax-expat-perl libxml-sax-perl
libxml-simpleobject-libxml-perl perl-openssl-defaults postfix
Running newaliases
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /lib/systemd/system/postfix.service.
Setting up libwww-robotrules-perl (6.02-1) ...
Setting up libhttp-daemon-perl (6.06-1) ...
Setting up libsys-hostname-long-perl (1.5-1) ...
Setting up libhtml-form-perl (6.07-1) ...
Setting up libnet-ssleay-perl (1.88-2ubuntu1) ...
Setting up libxml-sax-perl (1.02+dfsg-1) ...
update-perl-sax-parsers: Registering Perl SAX parser XML::SAX::PurePerl with priority 10...
update-perl-sax-parsers: Updating overall Perl SAX parser modules info file...
Creating config file /etc/perl/XML/SAX/ParserDetails.ini with new version
........................................................
Step 4: Check iwatch version
After successful installation, you can check the current installed version by using iwatch --version
command. As you can see from below output, current version is 0.2.2
.
root@localhost:~# iwatch --version
iWatch 0.2.2, a realtime filesystem monitor.
Cahya Wirawan <cahya at gmx dot at>, Vienna 2006.
Step 5: Using iwatch
Now that iwatch is available in your System, you can use it monitor the events on your System files and directories. For example, here we are monitoring all the events on /tmp
filesystem using iwatch -e all_events /tmp
command. You can check more about iwatch usage on Ubuntu iwatch Manual Page.
root@localhost:~# iwatch -e all_events /tmp
[15/Nov/2021 20:01:04] IN_ISDIR,IN_OPEN /tmp
[15/Nov/2021 20:01:04] IN_ISDIR,IN_ACCESS /tmp
[15/Nov/2021 20:01:04] IN_ISDIR,IN_ACCESS /tmp
[15/Nov/2021 20:01:04] IN_ISDIR,IN_CLOSE_NOWRITE /tmp
[15/Nov/2021 20:01:21] IN_ISDIR,IN_OPEN /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] IN_ISDIR,IN_ACCESS /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] IN_ISDIR,IN_CLOSE_NOWRITE /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] IN_ISDIR,IN_OPEN /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] IN_ISDIR,IN_ACCESS /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] IN_ISDIR,IN_CLOSE_NOWRITE /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] IN_ISDIR,IN_DELETE /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg
[15/Nov/2021 20:01:21] * /tmp/systemd-private-9a1e25045eda4a3e8da01c31b59d372d-apache2.service-0vavPg is deleted
Step 6: Uninstall iwatch (Optional)
You can also choose to uninstall iwatch if it is no longer required in your System. Although I won't recommend it but still if you want to remove this then you need to simply run apt-get remove iwatch -y
command to remove the package as shown below.
root@localhost:~# apt-get remove iwatch -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libcommon-sense-perl libevent-perl liblinux-inotify2-perl libmail-sendmail-perl libsys-hostname-long-perl libxml-simpleobject-libxml-perl
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
iwatch
0 upgraded, 0 newly installed, 1 to remove and 93 not upgraded.
After this operation, 63.5 kB disk space will be freed.
(Reading database ... 200673 files and directories currently installed.)
Removing iwatch (0.2.2-7) ...
Processing triggers for man-db (2.9.1-1) ...