近日调试程序,因为CGP的服务器要求复制更新文件后需要重启才能使文件生效,所以每次更新文件都需要手工重启一下CGP服务器,甚是麻烦,所以使用几个简单的命令,写了个shell,用着挺省心,贴上源码:
#!/bin/sh
#define path to be watched
SPY_PATH=/var/CommuniGate/Domains/ruyi.com/WebSkins
#create file tap.lst and initial it
if [ -f "tpa.lst" ]; then
echo -n ""
else
echo "---" > tpa.lst
fi
#loop and pause serveral seconds
while [ 1=1 ]; do
line=
ls -ltr --time-style=full-iso $SPY_PATH | grep -E ".wss|.js" > tp.lst
tail -n1 tp.lst > tpo.lst
line=$(cmp tpo.lst tpa.lst)
if [ -n "$line" ];
then
rm -f tpa.lst
cp tpo.lst tpa.lst
#restart CGP Server (stop then start), the command can be replaced with other commands you need
/etc/init.d/CommuniGate stop
/etc/init.d/CommuniGate start
echo ""
echo -n "=========================================="
echo $(date +"%F %X")
else
echo -n ""
fi
#echo -n "loop....."
sleep 3
done
exit 0