linux shell检测文件变动,重启swoole或xx
#!/bin/bash
# 文件目录
fileDir=/www/wwwroot/demo/
# 设置需要检测的文件
fileName=ci_mark
# 获取当前文件最后编辑时间戳
initTime=`stat -c %Y $fileDir/$fileName`
# 循环查询文件最后编辑时间是否变化
while true
do
changeTime=`stat -c %Y $fileDir/$fileName`
if [ $changeTime -ne $initTime ];then
initTime=$changeTime
echo $(date +%F%n%T) $fileDir/$fileName 'has been changed'
# 杀掉进程
ps aux | grep swoole | awk '{print $2}' | xargs kill -9
# 运行新的文件
cd /www/wwwroot/demo/laravel
php artisan swoole:action start
fi
# 检测间隔
sleep 5
done
码字很辛苦,转载请注明来自感触life-博客的《linux shell检测文件变动,重启swoole或xx》
评论