Showing posts with label Command Line. Show all posts
Showing posts with label Command Line. Show all posts

Tuesday, February 9, 2010

Start your wireless connection before Ubuntu login

Recently I started asking myself how I could get Ubuntu to forge its wireless connection (with WEP encryption) to my router without having to log-in through the GUI. I noticed that the default way of logging in through the GUI and then having a wireless connection available was limiting for two reasons: (1) If I wanted to be able to connect to my openSSH server then I needed to be logged in, and (2) If there was something wrong with the GUI and I had to log-in through the command line then I wouldn't have internet access.

So I started looking around on the net. Most pages that I found showed messageboard threads suggesting modifications to the /etc/network/interfaces file. This is the file that is supposed to tell your Linux system what to do with your network interfaces at boot-up. I tried to modify it so that my wireless card would start-up with a static IP at boot-up, but no matter how I changed this file, nothing worked.

Finally, I decided to ask a question on ubuntuforums. I found out that Gnome Network Manager, the program in Ubuntu which manages all your wired and wireless network connections, works terribly with the settings in the /etc/network/interfaces file. In other words, if you want Ubuntu to start your wireless connection at bootup instead of after login, you have to get rid of Gnome Network Manager!

So, on the advice of chili555 from ubuntuforums, I got rid of Gnome Network Manager by typing in sudo apt-get remove --purge network-manager and modified my /etc/network/interfaces file to look like the following (SSID and WEP key changed for privacy):

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.2.11
netmask 255.255.255.0
gateway 192.168.2.1
wireless-essid MYSSID
wireless-key 12345678912345678912345678

iface eth0 inet dhcp


Now, every time I start my computer, my wireless connection is available before login so that I can login to my openSSH server or go to the command-line without logging in to the GUI!

Tuesday, January 19, 2010

How to screw up then fix Gnome in Ubuntu!

Yesterday I read about a supposedly nice-looking patched version of Nautilus and decided to try it out. I installed it, used it for a few hours before bed, and realized that I really hadn't gained anything special by installing it.

When I uninstalled it this morning, I really screwed up my installation of gnome. So much so that I simply couldn't log into ubuntu using the Gnome Display Manager (the meat and bones of the Ubuntu Grahpical User Interface). Thankfully, I still had access to the Virtual Console by pressing Control+Alt+F2 at the login screen.

One thing I learned is that I still don't know how to initialize an ethernet connection to my router/DSL modem to give me an internet connection from the command line. I know that you can set your ethernet interface's IP address by typing in sudo ifconfig eth0 address and you can substitute address with netmask address to change the netmask (I think it's usually 255.255.255.0 on most consumer routers). That didn't work for me however. I also tried toying with the route command, but I really didn't understand how to work with that.

What ended up saving me was a suggestion that I read on ubuntuforums.org, in response to someone in a similar situation, that they should download an alternative ubuntu installation iso, burn it to CD and use it as a source for package updates. I didn't end up burning it to CD. Rather, I did the following:
  1. downloaded it to my USB stick
  2. mounted the ISO in a newly made separate directory directory (using the command sudo mount -o loop ubuntu-9.10-alternate-i386.iso /media/testing)
  3. navigated to that directory (cd /media/testing)
  4. switched bash into root mode (sudo bash -i)
  5. Finally I initialized an upgrade from the mounted Alternative Install ISO (./cdromupgrade)
The alternative install ISO fixed my broken GNOME/Nautilus packages, restarted my computer and .... VOILA! Everything was back to normal! Nothing was lost and I'm now a happy camper.

I'm definitely going to keep an alternative install ISO on me and probably also a regular install ISO too. After-all, they are free tools that don't even need to be burned to CD.

Tuesday, January 12, 2010

Search Workopolis Easily with Python

I've been looking for jobs lately and thought how nice it would be if I could skip the rigamarole of opening up my browser, going to a job search website, typing in the search arguments, and sifting through the results. In view of making job searching a little easier, I've made a Python script that for now will search Workopolis.com using keywords and a city location that you, the user, specify. It will then output a csv (comma separated value) file containing the job search results in the directory where you executed the script. You can then open the search results at your leisure, sift through them without the annoyances of advertisements, and possibly add them to your own database.

Just like pyBloggerU, I've uploaded the files for this Python script to launchpad for others to see and modify at their leisure. Go here if you'd like to download the program files, and here if you'd like to read more and possibly contribute to the project!

Once you put the program files in a particular directory, go to your command line, type python PyJobFinder.py, and then answer the questions that it asks you. Quickly after putting in your search terms, the program tells you the file name of the job results file and then you're free to open it up!

Friday, December 25, 2009

Schedule a delayed shutdown

Several times I've initiated a download of a big movie file late at night before I go to bed.  Without knowing anything else, I'd normally have to leave my computer on all night just so that I could download that movie file that will probably only take up 3 hours.  Wouldn't it be nice if you could tell your computer to turn off after the time it takes to download something?

That's where the shutdown command in bash comes in handy!  Here's an example of the way I usually use it:

sudo shutdown -P 300

Firstly, you need to have root access to use shutdown, hence my use of the sudo command.  I used -P to indicate that I want to power off after shutdown (as opposed to rebooting, or 'halting').  Finally, I typed 300 to indicate that I want the computer to shutdown in 3.5 hours (300 minutes).

Another way you can use the command is by specifying the clock time at which you want your computer to shutdown in 24 hour format.  So let's say you want your computer to shut down at 4:15pm:

sudo shutdown -P 16:15

Type that in and your computer will shut down at 4:15pm.  That's it!

Monday, December 21, 2009

Finding Files in Google Desktop and bash

    Sometimes I want to find a file and I have no clue where it is.  When I was using Windows Vista, this was a simple matter of using the native file searching utility, which dutifully searched for my lost file using the index it created of my hard drive.  File indexing is an amazing thing to take advantage of.  When your computer searches a file index, it gets results FAST! 

    If you don't have a file index (remember, it's literally a simple listing of every single file you've put on your computer in one relatively small database file) then your computer will have to loop through every single file on your computer, trying to match your search argument (e.g. 'Resume*.pdf') to the file names that it processes.

Today I'll talk about three linux programs for indexing and/or finding your files:
  • Google Desktop (for easy indexing and finding using a GUI)
  • locate (for finding indexed files in bash/terminal)
  • find (for finding files in bash/terminal)



Google Desktop

Even if you are using windows, click on the link above and get this program.  It's VERY convenient to use!  Google Desktop will not only allow you to search for your files, but emails that you've sent and received as well!  Once you download it, you will want to make sure that it builds an index of the directories in which your important files will be stored.  As shown below, right click on the Google Desktop icon and click on Preferences.  On my computer I have it indexing my home user directory and my USB drive root directory.  You can of course add any extra folders you like by click on Add folder to search.


Preferences are opened in your default browser

You may want to modify settings in the other tabs shown above.  Go to the Gmail tab and follow the instructions there if you would like Google Desktop to index your gmail account.  Also, go to Display and click on the Change Hotkey button lower down on the page in order to set up a key combination that will bring up a quick search box (shown below).


My key combo:    Shift+Control+?


When you're sure that everything is set, click on Save Preferences and Google Desktop will start indexing your files!  Bear in mind that the process is slow, so you'll have to give it several hours until it's done indexing everything.  You can check on Google Desktop's progress in indexing by right-clicking on the Google Desktop icon, then on Index, then on Index Status.  You'll then see its progress in indexing all of your files and emails.

What I really like about Google Desktop is the simplicity in finding and opening anything on your computer.  Type your key combo, quick search box comes up, type in your search argument, click on the result matching the file you were looking for, then your file opens!



locate

As I understand it, Ubuntu 9.10 (and i'm sure basically every other distro of Linux) indexes all my files for me on some periodic basis.  This is what enables the locate program to work in the terminal.  locate searches through the generated file index database for a term of your choosing.  So let's say I want to search for the manual I recently downloaded for my Hammer Drill, but I have no clue where it went!  Here's how I would use the command to find my file:

inkhorn@inkhorn-laptop:/$ locate -i hammer

Here's what the arguments I used mean:

  • -i tells the locate program to ignore the case of your search term
  • hammer is simply the search term

Here is the output from the locate command:

/home/inkhorn/Documents/Hammer Drill Manual.pdf
/usr/share/pixmaps/pidgin/emotes/default/hammer.png
/usr/src/linux-headers-2.6.31-15/arch/avr32/boards/hammerhead
/usr/src/linux-headers-2.6.31-15/arch/avr32/boards/hammerhead/Kconfig
/usr/src/linux-headers-2.6.31-15/arch/avr32/boards/hammerhead/Makefile
/usr/src/linux-headers-2.6.31-16/arch/avr32/boards/hammerhead
/usr/src/linux-headers-2.6.31-16/arch/avr32/boards/hammerhead/Kconfig
/usr/src/linux-headers-2.6.31-16/arch/avr32/boards/hammerhead/Makefile

The first result is the one I'm looking for!  Now I know where to look to open my hammer drill manual.



find

The find command has to loop through each and every file in the directory you specificy in your search argument.  If you told it to search the root directory '/' for a file with the word 'Hammer' in it, your computer would probably take an intolerably long time finding it.  Happily enough, you don't need to do that and probably have an idea generally where it is.  To use my hammer drill example:

inkhorn@inkhorn-laptop:/$ find /home/inkhorn -iname 'Hammer*.*'

Here's what the arguments I used mean:
  • -iname tells find to ignore case when comparing your search argument string to the file names that it loops through
  • 'Hammer*.*' tells it to look for a file of any extension (.*) starting with the word 'Hammer' and continuing with any other words after that (*)

Here is the output from the find command:

/home/inkhorn/Documents/Hammer Drill Manual.pdf

Cool thing is that the find command only outputs file results while the locate command outputs directory results!  In this instance, the results came on screen really quickly.

Now for something even cooler:  I can enter in a command that looks for a file that I'm interested in and opens it in a program that reads it!  Here is what I would enter in if I wanted to look for the hammer drill menu in terminal and automatically open it up in an excellent PDF reader named Okular:

inkhorn@inkhorn-laptop:/$ find /home/inkhorn -iname 'Hammer*.*' -type f -exec okular '{}' \;

You've already seen the first part of the find command in action.  The second part tells the find command to execute a program called 'okular' that should then take the find results as an argument.  In other words, okular opens up the file listed in the find output.

You can use this to open up other file types that you want to find.  If you're looking to open a word document, replace 'okular' with 'oowriter', a spreadsheet, replace 'okular' with 'oocalc'.

For more info on using find and locate, click here.