LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
LinkBack Search this Thread
Old 01-06-2010, 04:31 AM   #1
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 140Reputation: 140
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
 
Old 01-06-2010, 04:40 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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.
Old 01-06-2010, 04:42 AM   #3
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 140Reputation: 140
Quote:
Originally Posted by EricTRA View Post
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?
 
Old 01-06-2010, 04:48 AM   #4
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 01-06-2010, 04:53 AM   #5
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 140Reputation: 140
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.
 
Old 01-06-2010, 04:57 AM   #6
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 01-06-2010, 04:59 AM   #7
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 01-06-2010, 05:10 AM   #8
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 140Reputation: 140
Quote:
Originally Posted by EricTRA View Post
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.
 
Old 01-06-2010, 05:14 AM   #9
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 01-06-2010, 05:16 AM   #10
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Slackware 14.0
Posts: 8,464

Rep: Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877
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
 
Old 01-06-2010, 05:19 AM   #11
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 140Reputation: 140
Quote:
Originally Posted by EricTRA View Post
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.
 
Old 01-06-2010, 05:20 AM   #12
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 140Reputation: 140
Quote:
Originally Posted by repo View Post
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
 
Old 01-06-2010, 05:22 AM   #13
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 01-06-2010, 05:23 AM   #14
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Slackware 14.0
Posts: 8,464

Rep: Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877
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
 
Old 01-06-2010, 05:40 AM   #15
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 140Reputation: 140
Quote:
Originally Posted by repo View Post
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.
 
  


Reply

Tags
bash, command, sequence


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
some problems related to Linux usage amit12sept Linux - Newbie 1 11-05-2008 06:49 AM
A couple of questions about command line usage MasterOfTheWind Linux - General 14 10-04-2007 01:20 PM
Bash command questions xeon123 Linux - General 2 09-20-2007 02:58 PM
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 11:50 AM
2 bash related questions mobilemonkey Slackware 10 05-25-2007 06:28 PM


All times are GMT -5. The time now is 12:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration