duancong6937 2018-03-06 14:32
浏览 65

用于检索cron服务状态并在网页上显示状态的脚本

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:

  1. How to incorporate exception handling so the user sees an error message on the web page if something goes wrong.

  2. I intend to use this script to connect with multiple PIs - so how can I reuse variables to improve code quality?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100