I have the following cron service running on various PI's to display videos on loop:
Loaded: loaded (/etc/init.d/surround.sh)
Active: active (running) since Tue 2018-02-27 11:49:32 IST; 1 weeks 0 days ago
Process: 432 ExecStart=/etc/init.d/surround.sh start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/surround.service
442 python /usr/sbin//surround -f
14588 player.bin /var/lib/Videos/test_vid1.h264 /var/lib/Videos/test_vid1.h264 /var/lib/Videos/test_vid1.h264...
From my CMS server how can I implement a bash script that connects to each PI over SSH and retrieves the status of the surround service and then displays the status onto a web page. So if the service is currently running, I'd like the webpage to show 'Active' next to each PI's name.
The schedule for the video is stored as a .json file:
{"config": {}, "schedule": [{"start": "2017-06-15", "end": "2017-12-15","order": 1, "filename": "test_vid1.h264"}, {"start": "2017-06-15", "end":"2017-12-15", "order": 2, "filename": "test_vid1.h264"}, // and so on..
If anyone can find an easier way to achieve this by using a different tool, e.g. PHP, JavaScript etc. I can work around.
UPDATE
Based on the feedback I have put together a PHP script:
<?php //dashboard.php
$command = "ssh -p 97 -i PI12.rsa pi@192.xxx.xx.xx tail -5 /var/log/vidlog.csv ; sudo service surround status ;
$output = shell_exec($command);
echo "<pre>$output</pre> ";
?>
My question is, how can I improve my script further? Specifically I'd like to focus on the following two points:
How to incorporate exception handling so the user sees an error message on the web page if something goes wrong.
I intend to use this script to connect with multiple PIs - so how can I reuse variables to improve code quality?