截断日志,保存最后10行
echo "$(tail -n 10 filename.log)" > filename.log
监控日志,执行特定命令
tail -fn0 /root/.klei/DoNotStarveTogether/Cluster_1/Master/server_log.txt | \
while read line ; do
echo "$line" | grep "Sim paused"
if [ $? = 0 ]
then
# cpulimit -e dontstarve_dedicated_server_nullrenderer -l 7 -b
echo "$line"
curl https://*?text=世界暂停了 2>/dev/null
fi
echo "$line" | grep "Sim unpaused"
if [ $? = 0 ]
then
# curl https://*text=世界恢复了
echo "世界恢复正常了["`date`"]"
fi
echo "$line" | grep "Client authenticated:"
if [ $? = 0 ]
then
url="https://*"
curl \
--data-urlencode "text=玩家进入世界" \
--data-urlencode "desp=$line" \
$url 2>/dev/null
fi
done
Written with StackEdit.
Comments