我有一个简单的脚本,用于设置日志记录,tail -f
在日志文件上运行,然后在退出tail
后执行一些清除操作。基本上是这样的
echo 'monitoring started'
tail -f /var/log/some.log
echo 'never gets here'
问题是,tail
按Ctrl + C退出也会中断脚本执行,因此不调用清理。有没有一种方法可以“适当地”退出tail
并恢复脚本调用?我发现了一些基于保存PID并通过超时将其杀死的解决方案,但这不是我想要的,我可能需要监视几分钟或几小时,因此我想进行手动切换。
你可以做这样的事情
echo "monitoring started"
tail -f /var/log/some.log & #execute tail in background
read -sn 1 #wait for user input
kill %1 #kill the first background progress, i.e. tail
echo "Is reached"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句