小编cog*_*1v3的帖子

在 Ctrl+C 上,终止当前命令但继续执行脚本

我有一个 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)

shell bash signals trap

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

bash ×1

shell ×1

signals ×1

trap ×1