This commit is contained in:
xyj 2023-12-02 18:32:17 +08:00
parent f5c5e6945c
commit 653e340758
4 changed files with 15 additions and 4 deletions

View File

@ -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)

8
cron_delete_mp4.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# 设置文件保留时间为2天
DAYS=2
# 使用find命令查找所有符合条件的文件
find /home/pi/mp4 -type f -mtime +$DAYS -exec rm -f {} \;

View File

@ -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 ]]

View File

@ -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"]