3 related questions on bash command usage.
Hello all.
I am using aircrack-ng to perform testing on my network, using Ubuntu 9.10. However that is not what my question is about, just a little background info. This may not seem to fit in this section of the forum, but it does (read whole post). I will try to make this as short and well explained as I can, but go ahead and ask if I miss something. What I am trying to do is make a shortcut in the GNOME menu for a few particular commands. I know how to do that rather easily; but keep that in mind before you ask "why not just do it the other way?" I feel I may learn something from it while making this handy shortcut, so I feel the need to post here, since this compound issue is a bit hard to Google out. Forgive me if I am wrong. To use aircrack-ng, I have to put my wireless card into monitor mode, which works, but with a loophole. I have to click on Network Manager and disable networking first. Now I know that many of you don't use Ubuntu or Network Manager, so unless you know what I am talking about, assume what I am saying here is not allowing Linux to associate with any of the AP's, without turning the card "off" or disallowing any other features temporarily. So my first question is how do I do that in the command line? After that, what I do is more simple: Code:
(Answer to first question) Do you use a "|" in between each command like so: Code:
sudo su | ifconfig wlano down | iwconfig wlano mode monitor Or do you use a ";" in between commands like so: Code:
sudo su; ifconfig wlano down; iwconfig wlan0 mode monitor My third question is much simpler, will this work? (If my commands are a little messed up, it's because I haven't used aircrack for quite some time) Thanks |
Hello,
You can put all the commands in a file and make it executable. That way all command will be executed line by line one after the other. Then in your Gnome, call that script. If you want to execute commands sequentially on one line use the && operand like this: Code:
sudo su && ifconfig wlano down && iwconfig wlano mode monitor If it will work? Don't know, why don't you try it out? Run the commands from a terminal to see what they do and where (if) they fail before putting them in a shell script. Solve each problem first so that you don't have to troubleshoot the whole script at once without knowing which part fails. You might want to take a look into this guide to learn all about Bash scripting: Bash Guide for Beginners Kind regards, Eric |
Quote:
|
Hi,
Calling Code:
/etc/init.d/networking stop Kind regards, Eric |
Hi.
Si I made the beginnings of my script: Quote:
Quote:
|
Hi,
Delete the sudo su part from the script and enter a su console manually, then run the script without the sudo part to see if the rest works. That way you can make sure that the sudo su part is the culprid. I have almost never used sudo (I'm always root), so don't really know how to bypass it. Kind regards, Eric |
What you could do, if I remember correctly is change the SUDOERS file to list this command in order to be executed by you without a password. Also that way you could call the commands directly using sudo and without entering a su shell.
Kind regards, Eric |
Quote:
The /etc/init.d/networking stop command seemed to not work. Console output: Code:
root@mylinuxbox:/home/andrew# /etc/init.d/networking stop So to answer your question, I don't think the script actually worked, unfortunately, unless I have done something wrong. (which is plausible) What I did is change the script to include a command that would produce output. Code: Code:
#! /bin/bash |
Hi,
Just noticed something. You've got wlan0 that you want to operate on, the wireless interface. If I'm not mistaking that doesn't get handled by the networking script. Try this and see if you get the result you want: Code:
sudo service network-manager stop Eric |
Are these commands working? the way you want it?
Quote:
If yes, put them in a script and run it as root |
Quote:
This command worked to perfection, so now all thats left is to figure out whats wrong with my script and how to bypass sudo su. |
Quote:
|
Check out the SUDOERS file. In there you can set options to use with commands when executed by certain users. So if you put in there that for your user, when executing the commands in that script no sudo password should be asked, then it would run in my opinion. But again, I'm not very familiar with sudo so if you encounter any problems with it, just post them here and I'm sure someone will give you an answer (or just out of curiosity I might look into it).
Kind regards, Eric |
Try this, and run it as root from a terinal
Quote:
|
Quote:
I wasn't sure where to find the SUDOERS file so I did a search in nautilus as root and it found many, many files. One that I came across had this: Code:
# /etc/sudoers |
Hi,
That indeed is the sudoers file, but don't just edit it like that. You have to use: Code:
sudo visudo Code:
id Kind regards, Eric |
Also, what would be very useful to you is to look at the sudoers man page:
Code:
man sudoers Kind regards, Eric |
Quote:
"id" returns: Code:
andrew@mylinuxbox:~$ id |
Quote:
Code:
sudo su Code:
sudo yourscriptname Eric |
Thanks Eric!
That did the trick. I made a GNOME menu entry and used "gksudo /home/andrew/Desktop/airodump-ng_auto" (airodump-ng_auto was my script name) and it worked like a charm. I attached a few screenshots of the script in action! |
Hello Andrew,
Glad you got it running as you wanted. If you consider your thread as solved please mark it as such using the Thread Tools. Kind regards, Eric |
Quote:
Here is the script that I used for future reference of this thread. Code:
#! /bin/bash |
&& vs ||
Also note that you join commands with && if you want to stop the sequence if any of the commands fail. "echo 1 && echo 2" means echo 1 and if that statement succeeds, then run the command "echo 2" and on and on any number of commands. On the other hand "echo 1 || echo 2" means run "echo 1" and then only if that fails, run "echo 2"
And if you really don't care what the return status is or the return status is undefined (unlikely on Linux but very prevalent in Windows) then just use the semicolon (";"). |
it looks great to me i am curious to know further.
|
All times are GMT -5. The time now is 08:42 PM. |