diff --git a/MQTT.py b/MQTT.py index 501de0f..36b02c5 100644 --- a/MQTT.py +++ b/MQTT.py @@ -29,6 +29,8 @@ class MQTT: # git更新项目和配置文件 update() client.publish('success', payload='update success', qos=0) + elif data == "record": + get_record(msg) else: client.publish('error', payload='No Such Type', qos=0) diff --git a/cron_delete_mp4.sh b/cron_delete_mp4.sh new file mode 100644 index 0000000..1a04e16 --- /dev/null +++ b/cron_delete_mp4.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# 设置文件保留时间为2天 +DAYS=2 + +# 使用find命令查找所有符合条件的文件 +find /home/pi/mp4 -type f -mtime +$DAYS -exec rm -f {} \; + diff --git a/delete_than24.sh b/delete_than24.sh index ec7e983..690b7a2 100755 --- a/delete_than24.sh +++ b/delete_than24.sh @@ -4,13 +4,11 @@ set -e folder="/home/pi/mp4" # 获取文件夹的大小 -size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}') -echo $size +size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}') while [[ $size -gt 24 ]] do # 获取最早创建的文件 oldest_file=$(ls -tr | head -1 | xargs) - echo $oldest_file rm -f $oldest_file size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}') if [[ $size -le 24 ]] diff --git a/tool.py b/tool.py index dbeedae..e52ee8b 100644 --- a/tool.py +++ b/tool.py @@ -12,9 +12,12 @@ def close_stream(): def exec_sh(msg): cmd = json.loads(msg.payload.decode('utf-8'))["data"] - subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) def update(): subprocess.Popen(['/bin/bash update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + +def get_record(msg): + time = json.loads(msg.payload.decode('utf-8'))["data"]