Question

I'm working on a bash script to test access points. To end sudo airmon-ng start wlan0 && sudo airodump-ng mon0 -- Ctrl + C needs to be pressed, this cancels the entire script, instead of continuing. How can I get it to continue after 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
Was it helpful?

Solution

Set up a trap, like this:

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


trap int_trap INT

echo "Enter line or press Ctrl-C"

xterm

echo "Continuing the script"

See the bash manpage for more info and usage examples in e.g. /usr/bin/bashbug. Be careful however, the traps may prevent your script from exit cleanly when it's really needed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top