bashoutputkillaircrack-ng

Is possible to stop a command stopped in a read or prompt?


In my Bash script I must launch a command (aircrack-ng) to recover the output in a var for using it later. The target is to parse the output of a .cap file in order to know if there is some kind of data (handshake for WPA networks).

The problem is this command sometimes (depending of the file you want to parse), is stopping prompting the user for choosing one option. If the file has only data from one network it doesn't stop. If the file has different network data, it stops.

I already have the output of the command parsed, but the problem is the script stops. I would kill the command immediately after launched and recovered the output to the var and don't want the script stops.

I tried to launch it with & at the end to run in background and then killing it, but it stops anyway.

nets_from_file=$(aircrack-ng /path/to/somefile.cap 2> /dev/null | egrep "WPA \(1" | awk '{ saved = $1; $1 = ""; print substr($0, 2) }' &)

kill -9 $(ps aux | grep aircrack-ng | grep -v "grep" | awk '{print$2}') > /dev/null 2>&1

Is there a way to launch first command what is causing a stop, recover the output and kill that command without stopping script?


Solution

  • woow... I found it! amazingly simple after a headache...

    nets_from_file=$(echo "1" | aircrack-ng /path/to/somefile.cap 2> /dev/null | egrep "WPA \(0"  | awk '{ saved = $1; $1 = ""; print substr($0, 2) }')
    

    a simple echo before with pipe did the trick! :)