开发者

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 result开发者_高级运维s).

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜