按Ctrl + C后继续运行脚本

时间:2014-03-31 01:53:45

标签: bash controls

我正在使用bash脚本来测试访问点。结束 sudo airmon-ng start wlan0&&需要按下sudo airodump-ng mon0 - Ctrl + C ,这会取消整个脚本,而不是继续。如何在 Ctrl + C 之后继续它?

# Stop Services To Fix Conflicts
service network-manager stop
service avahi-daemon stop
killall wpa_supplicant
clear

# Scan For Access Points
sudo airmon-ng start wlan0 && sudo airodump-ng mon0

# Restart Networking Services
sudo airmon-ng stop wlan0
sudo aitmon-ng stop mon0
sudo service network-manager start
sudo ifconfig wlan0 up

1 个答案:

答案 0 :(得分:7)

设置陷阱,如下所示:

int_trap() {
    echo "Ctrl-C pressed"
}


trap int_trap INT

echo "Enter line or press Ctrl-C"

xterm

echo "Continuing the script"

有关详细信息和用法示例,请参阅bash联机帮助页。在/ usr / bin中/ bashbug。但要小心,陷阱可能会阻止脚本在真正需要时干净利落地退出