If you want to monitor the services running on your linux machine you have a lot of options. But if you don’t want to install any additional software or applications, you can do it with a very simple perl script. (you need MIME::Lite to be installed before you can use this).
In order to install MIME::lite you have to run cpan -i MIME::Lite or open a CPAN shell by running:
perl -MCPAN -e shell and then issuing: install MIME::Lite
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/usr/bin/perl use strict; use warnings; use MIME::Lite; #define email address my $email = 'user@domain.tld'; #define services to be monitored my @services = ('httpd', 'mysql', 'pure-ftpd', 'named', 'lfd', 'exim', 'authdaemond', 'crond', 'spamd', 'upsd', 'snmpd', 'mrtg', 'pptpd', 'vnstatd', 'mrtg', 'monit', 'nagios'); my $host = `/bin/hostname`; chomp $host; foreach my $service(@services) { my $status = /bin/ps cax | /bin/grep $service; if (! $status) { print "ALERT! $host: $service not running\n"; } } my $msg = MIME::Lite->new ( Subject => 'Service monitor for $host', From => 'root@host', To => $email, Type => 'text/html', Data => '', ); $msg->send(); |
Run the script. If any of your services is not running you will be shown a message on the screen and also an email will be sent to you. The script is really basic and can be highly customized according to your needs.
Have fun!