Results 1 to 6 of 6
i wrote 3 scripts though all need to have the same variables. which the variables may change and i rather change one file than 3. I cannot find out how ...
- 08-27-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 3
Bash Script, Variable reference trouble
i wrote 3 scripts though all need to have the same variables. which the variables may change and i rather change one file than 3. I cannot find out how or if it is possible to have one txt file or bash file just containing the variables and all three scripts will refer to the variables inside that one file.
Also, since it is 3 scripts, all are for terminal bassed programs. Is there a way to make a script to run all at the same time but one in each terminal. for example, running script.sh will open a terminal and run script1.sh and open another terminal and run script2.sh as well as another terminal for script3.sh at the same time.
This is the scripts.
Code:#!/bin/bash USERNAME="" CHANNEL="" BSSID="xx:xx:xx:xx:xx:xx" ESSID="" if [ "$ESSID" = "" ]; then airmon-ng stop ath0 airmon-ng start wifi0 airodump-ng ath0 else airmon-ng stop ath0 airmon-ng start wifi0 mkdir /home/$USERNAME/Desktop/aircrack cd /home/$USERNAME/Desktop/aircrack airodump-ng -c $CHANNEL -w $ESSID --bssid $BSSID ath0 fi
Code:#!/bin/bash USERNAME="" CHANNEL="" BSSID="xx:xx:xx:xx:xx:xx" ESSID="" MYMAC="xx:xx:xx:xx:xx:xx" cd /home/$USERNAME/Desktop/aircrack aireplay-ng -1 0 -e $ESSID -a $BSSID -h $MYMAC ath0 aireplay-ng -3 -e $ESSID -b $BSSID -h $MYMAC ath0
PS this is all experimental. I am using this on my own network to test my script out. I am not that familiar with linux or writing scripts. i read a few tutorials and this was a way i'd like to try out what i learned.
- 08-27-2008 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Have all the variables defined in a file named, say, vars
In the script that needs access to the variables, put this line
. ./vars
right after #!/bin/bash.
- 08-29-2008 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 3
Thank you secondmouse,
However i was still unable to make this work. i made sure all the scripts were in the same dir as the variable file i named my variable file "variables" and i wrote the beginning of each script as
but it still didn't work. am i supposed to make the variables file a script or name it with a certain extenstion? because this is all i put in that fileCode:#!/bin/bash ../variables if [ "$ESSID" = "" ]; then airmon-ng stop ath0 airmon-ng start wifi0 airodump-ng ath0 else airmon-ng stop ath0 airmon-ng start wifi0 mkdir /home/$USERNAME/Desktop/aircrack cd /home/$USERNAME/Desktop/aircrack airodump-ng -c $CHANNEL -w $ESSID --bssid $BSSID ath0 fi
Thank you in advanceCode:USERNAME="myusername" CHANNEL="thechannel" BSSID="xxxxxxxxxx" ESSID="name" MYMAC="xxxxxxxxxx"
- 08-30-2008 #4Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Italian Prince, you gotta put a space between the two dots like this
. ./variables
the first . is equivalent to command source, that is, you can also use it like
source ./variables
- 08-30-2008 #5Just Joined!
- Join Date
- Aug 2008
- Posts
- 3
secondmouse,
Yes i didn't notice the space between the dots when you wrote it before. This did work and it worked great! You have helped solve my problem. Though i feel like im asking to much. Would you happen to know how to make a script open those two scripts but opening different terminals to run at the same time? i could imagin how to make it just open a terminal but now how to make the scripts run in the newly opened terminals
- 08-30-2008 #6Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Italian Prince, if you are using gnome, try this
gnome-terminal -x /path/to/script1
gnome-terminal -x /path/to/script2
This works great if script1 and script2 doesn't exit when running, for example
gnome-terminal -x top
If you need to see the running status of the script, you can add a sleep N to the end of the script. For example:
script1
#!/bin/bash
echo "script 1 running"
sleep 10
in the terminal, execute
gnome-terminal -x ./script1
But if you just need to run script1 and script2 in turn, you can always do that in the same terminal by
./script1 &
./script2


Reply With Quote