Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuing a script after Ctrl + C

Tags:

bash

controls

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
like image 777
Seaner992 Avatar asked Jan 10 '23 21:01

Seaner992


1 Answers

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

like image 144
user3159253 Avatar answered Jan 18 '23 00:01

user3159253