how do i start commands in new terminals in BASH script
Asked Answered
H

2

14

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?

Harold answered 25/3, 2011 at 18:58 Comment(0)
A
15

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.

Azerbaijan answered 25/3, 2011 at 19:8 Comment(3)
And what should I do if the command that I run needs to a higher privilege? Is it possible to supply user password along-with the command? Thanks.Lammergeier
@CoderaPurpa This can be done (not with a password) but it's very easy to make a mistake that ruins your system security. I can't fit a full explanation of how to do it correctly in this comment box. Please ask a new question.Azerbaijan
More terminals to try; lxterminal (for LXDE); Terminal (for MacOS, though it's probably not on your PATH by default)Cointreau
A
1

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

Almallah answered 25/3, 2011 at 19:3 Comment(1)
i see now about starting airodump in its own window, the other commands are not exact and incomplete. I plan on running quite a few things, seeing what my macbook would be vulnerable to on home wpa2 network and if i can capture the handshake and if it will pass some dictionary attacks. The problem is 'terminator -e <command goes here>' the terminal man page says '-e runs command instead of default shell' but then the script says 'terminator no such option'Harold

© 2022 - 2024 — McMap. All rights reserved.