Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
01-06-2010, 04:31 AM
|
#1
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Rep: 
|
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)
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
?
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
|
|
|
|
01-06-2010, 04:40 AM
|
#2
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,798
|
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
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
Kind regards,
Eric
Last edited by EricTRA; 01-06-2010 at 04:42 AM.
|
|
|
1 members found this post helpful.
|
01-06-2010, 04:42 AM
|
#3
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Original Poster
Rep: 
|
Quote:
Originally Posted by EricTRA
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
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?
|
|
|
|
01-06-2010, 04:48 AM
|
#4
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,798
|
Hi,
Calling
Code:
/etc/init.d/networking stop
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.
Kind regards,
Eric
|
|
|
|
01-06-2010, 04:53 AM
|
#5
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Original Poster
Rep: 
|
Hi.
Si I made the beginnings of my script:
Quote:
#! /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.
|
|
|
|
01-06-2010, 04:57 AM
|
#6
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,798
|
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
|
|
|
|
01-06-2010, 04:59 AM
|
#7
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,798
|
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
|
|
|
|
01-06-2010, 05:10 AM
|
#8
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Original Poster
Rep: 
|
Quote:
Originally Posted by EricTRA
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
|
Hi Eric.
The /etc/init.d/networking stop command seemed to not work.
Console output:
Code:
root@mylinuxbox:/home/andrew# /etc/init.d/networking stop
* Deconfiguring network interfaces... Ignoring unknown interface eth0=eth0.
Ignoring unknown interface wlan0=wlan0.
[ OK ]
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.
Code:
Code:
#! /bin/bash
ifconfig wlan0 down && iwconfig wlan0 mode monitor && lspci
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.
|
|
|
|
01-06-2010, 05:14 AM
|
#9
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,798
|
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
Kind regards,
Eric
|
|
|
|
01-06-2010, 05:16 AM
|
#10
|
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Slackware 14.0
Posts: 8,464
|
Are these commands working? the way you want it?
Quote:
(Answer to first question)
sudo su
ifconfig wlan0 down
iwconfig wlan0 mode monitor
ifconfig wlan0 up
airodump-ng wlan0
|
If yes, put them in a script and run it as root
|
|
|
|
01-06-2010, 05:19 AM
|
#11
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Original Poster
Rep: 
|
Quote:
Originally Posted by EricTRA
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
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.
|
|
|
|
01-06-2010, 05:20 AM
|
#12
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Original Poster
Rep: 
|
Quote:
Originally Posted by repo
Are these commands working? the way you want it?
If yes, put them in a script and run it as root
|
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
|
|
|
|
01-06-2010, 05:22 AM
|
#13
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,798
|
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
|
|
|
|
01-06-2010, 05:23 AM
|
#14
|
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Slackware 14.0
Posts: 8,464
|
Try this, and run it as root from a terinal
Quote:
#! /bin/bash
service network-manager stop
ifconfig wlan0 down
iwconfig wlan0 mode monitor
ifconfig wlan0 up
airodump-ng wlan0
|
|
|
|
|
01-06-2010, 05:40 AM
|
#15
|
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,019
Original Poster
Rep: 
|
Quote:
Originally Posted by repo
Try this, and run it as root from a terinal
|
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 05:41 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:53 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.
|
Latest Threads
LQ News
|
|