Remote Monitoring System with Minimum Coding

By | August 23, 2017

This is the example how to organize remote monitoring of processes running on Linux devices.
Let us create simple script which executes ps command, saves results in html file and uploads the file in http server. 2 arguments are required to run the script: the fist one is html file name without extension and the second one is http server IP address or fqdn.

if [ $# -ne 2 ]; then
# 2 arguments are required
# file name
# server IP or fqdn
   exit -1
echo "<html><title>process monitoring</title><body>" > "/tmp/$1.htm"
echo "Local time: $datetime<br><pre>" >> "/tmp/$1.htm"
ps -eo pid,ppid,%cpu,rss,vsz,comm,user >> "/tmp/$1.htm"
echo "</pre></body></html>" >> "/tmp/$1.htm"
curl -i -X POST --form filedata=@/tmp/$1.htm --form userid=qwerty \
https://$2/monitoring/mon.php > /dev/null 2>&1
rm -f "/tmp/$1.htm"

Save script as file and make it executable:

chmod 755

In other words the script is simple http client, which usually is not blocked by firewall.
Remote monitoring

Now we add script into cron scheduler with stat interval 5 minute.
Open crontab file as using command crontab -e and add the following line in the end:

*/5 * * * * /projects/ process

Where the first argument process is name of html file on the server side where data should be saved, the second argument is server name.

You may check in log file that the script is started periodically. On Ubuntu check /var/log/syslog file, on Centos /var/log/cron file.

# tail -f /var/log/syslog | grep ps_mon
Aug 22 20:40:01 smike19-VirtualBox CRON[18396]: (root) CMD (/Alex/projects/ process
Aug 22 20:45:01 smike19-VirtualBox CRON[18433]: (root) CMD (/Alex/projects/ process
Aug 22 20:50:01 smike19-VirtualBox CRON[18456]: (root) CMD (/Alex/projects/ process

Now open the Web browser you check the list of processes running on your Linux device. The URL is

Remote process browsing

If you want to monitor something else for example system disk space usage create similar script for df command, specify the first argument (file name) as df and the URL will be:

Pay attention the server adds short extension htm to html file.

You may use for remote monitoring, specifying your unique html file name. However if you want to configure your own server for collecting monitored data here is the server side php script:

if ( isset( $_POST['userid'] ) ) {
   echo $newfile;
   echo "\n";
   echo $_FILES['filedata']['size'];
   echo $tmp_file;
   if(move_uploaded_file($tmp_file, $newfile))
      echo "file moved";
      echo "failed";
else {
   echo "Not found";

Leave a Reply

Your email address will not be published. Required fields are marked *