-1

I am using a shell script to automatically search network access points, and in airodump you use ctrl + c to stop the search, and I am wanting to it cancel the search but keep my shell script running. Since I am wanting to do user input after I am done searching for wifi networks. I tried to use trap, and it stops airodump, and my script.

I am just wanting to stop airodump wifi search and move onto my shell script of user input.

Jolta
  • 2,620
  • 1
  • 29
  • 42
andyADD
  • 610
  • 1
  • 6
  • 20

1 Answers1

1

It's not entirely clear to me, but I believe you are wanting the user to be able to interactively stop the search via ctrl-C and then be prompted for input. This should do that:

#!/bin/sh

trap 'test "$airo" && kill -2 $airo' 2
airodump ... &
airo=$!
wait
unset airo

# Commands here will execute after the user hits ctrl-C to terminate the search
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • This is in the middle of my script, does this need to be in at the beginning of the script? O gave it a shot, and it still terminated the script too. I just want to end the airodump wifi search but not shell script, I mean it doesn't have to be ctrl+C since maybe thats causing conflict? – andyADD Feb 19 '13 at 22:47
  • If you send SIGINT (which is what ctrl-C normally does) before the trap is set, then the script will terminate. – William Pursell Feb 19 '13 at 22:57
  • what do you mean? do I need to type SIGNIT at the beginning of my script or what? I was able to use pkill command from seperate terminal and my script continued, so is there a way i can bind key to that command in the shell script? – andyADD Feb 19 '13 at 23:38
  • If you want to terminate the script, then you should type ctrl-C before the script sets a trap for SIGINT, but it sounds like you don't want to kill the script. It's not clear to me what exactly it is that you are doing that is terminating the script. Are you starting it and then immediately sending it a SIGINT? If so, and you do not want the script to terminate, then you should set the trap early in the script. – William Pursell Feb 19 '13 at 23:44
  • ok i put it at the beginning of the script, and works perfect but it sends an error like no such process i mean my script still continues but I am wanting to remove that error if possible. – andyADD Feb 19 '13 at 23:53
  • The error is happening either because airodump hasn't started yet, or it has already finished. I'll edit the answer to handle that situation gracefully. – William Pursell Feb 20 '13 at 00:02