[SOLVED] 3 related questions on bash command usage.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
sudo su
ifconfig wlan0 down
iwconfig wlan0 mode monitor
ifconfig wlan0 up
airodump-ng wlan0
My second question is how to format the above so that it is one streamlined command in which one is executed after another?
Do you use a "|" in between each command like so:
Code:
sudo su | ifconfig wlano down | iwconfig wlano mode monitor
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
The | is for piping output of one command into the next command.
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
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
The | is for piping output of one command into the next command.
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.
Kind regards,
Eric
That sounds like it work perfectly. But how do I do the said "disable networking" thing in the CLI?
on the console will stop networking if that's what you mean. You could also look at the networking script mentioned in the previous command to see what exactly it does.
#! /bin/bash
sudo su && ifconfig wlan0 down && iwconfig wlan0 mode monitor && ifconfig wlan0 up
And then Google'd how to make it executable and did so:
Quote:
chmod u+x /home/andrew/Desktop/airodump-ng_auto
And then I ran it, and it did not do anything after I entered my password. It seems that "sudo su" bit stalwarts the rest of the script from being executeable.
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.
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.
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
Hi Eric.
The /etc/init.d/networking stop command seemed to not work.
Console output:
Without that, the script won't be able to run correctly, because for some reason Linux decides to automagically reconnect to the network when I tell it to go "down" It only very quickly disconnects from the network and then reconnects.
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.
And when I clicked "Run" nothing happened. I tried it again, this time saying "Run In Terminal" and a Terminal window appear ever so quickly and dissappaered, having nothing changed.
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:
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
Kind regards,
Eric
Thanks again Eric.
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.
These command are working, sir. I was asking if putting them in a script and running as root would work. Apparently the script did not. See above posts to look at script. Thanks
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).
Hi. I re-did the file to those specifications, and it resulted in the said flashing of the terminal with no output or action. (It flashes very fast so I can't really see if anything happened but the command "airodump-ng" should result in sustained output)
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
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL)
Apparently I am of the admin group?
Last edited by lupusarcanus; 01-06-2010 at 06:41 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.