#!/bin/bash
file_path="/path" # 监视的文件的路径
command_to_pkill_execute="pkill soffice.bin" # 终止所有正在运行的LibreOffice实例
command_to_write_execute="libreoffice --writer" # 运行LibreOffice实例
# 获取文件的最后修改时间
last_modified=$(stat -c %Y "$file_path")
# 获取当前时间
current_time=$(date +%s)
# 计算最后修改时间距离当前时间的时间差(秒)
time_difference=$((current_time - last_modified))
# 判断时间差是否小于 300 秒(即 5 分钟)
if [ $time_difference -lt 300 ]; then
echo "文件在过去五分钟内已经修改,不执行命令。"
else
echo "文件在过去五分钟内未修改,执行命令:"
# 执行命令
$command_to_pkill_execute
sleep 5
$command_to_write_execute
fi
liunx 通过Shell脚本重新启动LibreOffice
于 2024-04-09 18:30:27 首次发布