Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i start commands in new terminals in BASH script

Tags:

bash

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?

like image 784
fightermagethief Avatar asked Mar 25 '11 18:03

fightermagethief


People also ask

How do I start a new terminal in bash?

Use the gnome-terminal Command to Start a New Terminal Session in Bash. You must use the simple command gnome-terminal to start a new terminal from an already running instance. This will start a new terminal instance, and a new window will open.

How do I open a new terminal tab in shell script?

Keyboard shortcut CTRL + ALT + T opens a new terminal window on Linux . By default it opens 1 new terminal window.


2 Answers

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.

like image 191
zwol Avatar answered Oct 24 '22 12:10

zwol


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?)

like image 35
Ernest Friedman-Hill Avatar answered Oct 24 '22 11:10

Ernest Friedman-Hill