我有一个 bash 脚本,其中我执行一行,睡眠一段时间然后tail -f我的日志文件来验证某个模式被看到,我按 ctrl + c 退出tail -f然后移动到下一行,直到 bash 脚本完成执行:
这是我迄今为止所做的:
#!/bin/bash
# capture the hostname
host_name=`hostname -f`
# method that runs tail -f on log_file.log and looks for pattern and passes control to next line on 'ctrl+c'
echo "==================================================="
echo "On $host_name: running some command"
some command here
echo "On $host_name: sleeping for 5s"
sleep 5
# Look for: "pattern" in log_file.log
# trap 'continue' SIGINT
trap 'continue' SIGINT
echo "On $host_name: post update …Run Code Online (Sandbox Code Playgroud)