fightermagethief
fightermagethief

Reputation: 322

how do i start commands in new terminals in BASH script

my bash script reads in a few variables and then runs airodump on my home network. I would like to keep the window with airodump running and open some new terminals to run other commands for network discovery while the airodump screen is open (so i can see the results).
right now what i have looks like this (edited for brevity):

#!/bin/bash
read -p "Enter the channel: $channel"
airomon-ng start wlan0 $channel,$channel
airodump-ng -c $channel,$channel mon0 &&
terminator -e netstat -ax &&
terminator -e nmap 192.168.1.1

the first command that uses the whole terminal (airodump) starts up fine and i can see the network, but then it just stays on that screen. If i ctrl+c then it goes back to prompt but i can see the error : Usage: terminator [options] error no such option
i want the netstat and nmap commands to appear and stay in their own terminal windows, how can i do this?

Upvotes: 14

Views: 29283

Answers (2)

zwol
zwol

Reputation: 140540

The terminal window is generated by a separate program from the command running inside. Try one of these variations:

xterm -e airomon-start wlan0 "$channel","$channel" &

gnome-terminal -x airomon-start wlan0 "$channel","$channel" &

konsole -e airomon-start wlan0 "$channel","$channel" &

Pick the command that invokes the terminal program you like. You'll have to do this for every command that you want run in its own window. Also, you need to use a single & at the end of each such command line -- not a double && -- those do totally different things. And the last line of your script should be just

wait

that makes it not exit out from under all the terminals, possibly causing them all to die.

Obligatory tangential shell-scripting nitpick: ALWAYS put shell variable uses inside double quotes, unless you know for a fact that you need word-splitting to happen on a particular use.

Upvotes: 15

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

If the script is running in the foreground in the terminal, then it will pause while an interactive command is using the terminal. You could change the script to run airodump in a new terminal as well, or you could run the background commands before you start airodump (maybe after sleeping, if you're concerned they won't work right if run first?)

Upvotes: 1

Related Questions