Reusing SSH connection

Linux, SSH August 25th, 2008

Very often, while working on a network node via SSH, we need multiple connections to the same node. For example, say you are connected to a node A, and then you need to transfer a file to the same node from your local machine. Then we have to scp, which establishes a fresh connection to that machine and one has to enter the password again. So, it takes some time as well as it is irritating to enter password again and again.

Here’s the remedy :

Open the file /etc/ssh/ssh_config on your local machine as root to edit. Or if you are not the root user, you can create a fileĀ  ~/.ssh/configĀ  for user level SSH configurations.

Add the following lines at the end of the file you opened just now:

ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p

Save the file and you are done !!

Now check out (One can try it this way) -Open a terminal and connect to a server :

$ ssh s.siddharth@202.141.81.145

The connection gets established after entering the proper password.

Then in another terminal try to copy a file from your local machine to the same server :

$ scp -r ~/pintos s.siddharth@202.141.81.145

This time, you don’t need to wait for a fresh connection, neither you will have to enter the password again. File transfer starts instantaneously. SSH shared the already established connection.
Similarly you can open another terminal without waiting and entering the password again.

One can check out more configurations for SSH by checking out the man pages of ssh_config
$ man ssh_config

Hope you liked this tip !!

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • Facebook
  • TwitThis
  • Live
  • Technorati
  • Furl
  • Sphinn
  • blogmarks
  • LinkedIn
  • Pownce

Download Files Larger Than The Download Limit

Linux, curl, proxy August 18th, 2008

Yesterday I had to download a file of size 232 MB. As I connect to the Internet via proxy and the authorities have restricted the file size download limit to 150 MB, I had to find some alternative. Similar scenarios are there in almost all Educational Institutions.

I was searching for the solution, somebody told me about JGet (a Multithreaded Java Software), but it hogs up a lot of system resources. I was in search of an alternate solution, then somebody on ##linux in irc.freenode.net told me about curl. Though I had heard of it earlier as well and I used it to automate web browsing like posting form data etc. But this time when I went through the man pages of curl, I realized how powerful is curl.

There are hundreds of options for CURL. I will just demonstrate you the one option which can help you download files of almost any size.

Lets start off…

In this example I am trying to download 32 Bit Fedora Live CD iso image. In this example, what we will do is download a part of file in one connection. After downloading all files we will concatenate them. This is what almost any Download manager software does.

To download a part of file theres an option -r/ --range available in curl which lets us specify the range of bytes of the file to be downloaded.

Range can be specified in following ways :
curl -r 0-499
This specifies to download first 500 bytes
curl -r 500-999
This specifies to download bytes starting from 500 to 999.
curl -r -500
specifies to download last 500 bytes.
curl -r 500-
specifies to download the bytes from offset 500 and forward

There are few more options. Check out the man pages. ( I have copied the simple options here).

Now here I have to download Fedora live CD iso which is 691 MB in size. So, I will download 100 MB in each connection, like this:
curl -# -r 0-99999999 -o fedora.iso.part1 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 100000000-199999999 -o fedora.iso.part2 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 200000000-299999999 -o fedora.iso.part3 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 300000000-399999999 -o fedora.iso.part4 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 400000000-499999999 -o fedora.iso.part5 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 500000000-599999999 -o fedora.iso.part6 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 600000000- -o fedora.iso.part7 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

In the above code -# is to suppress the details of progress meter. You can ignore this option.

After all the files are downloaded, we need to concatenate them. This is quite simple.

$ cat fedora.iso.part? > fedora-9-live.iso
And your live CD iso image is ready as fedora-9-live.iso
To verify the file has been downloaded and concatenated correctly you may verify the checksums before burning it to a CD/DVD.

This process could be automated if somehow by a simple shell script if we could get the file size before starting the downloaded. To accomplish this, I once again went through the man pages. And I found a useful option -I/ --head . This option fetches the HTTP-header only. One can easily get the file size as Content-Length from the HTTP headers. But, when I tried this through proxy servers I got a X-Squid-Error: ERR_TOO_BIG , so couldn’t determine the correct file size. And hence I am unable to automate the process. Anybody, any help ?? (please post it as comment).

Happy Downloading !!

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • Facebook
  • TwitThis
  • Live
  • Technorati
  • Furl
  • Sphinn
  • blogmarks
  • LinkedIn
  • Pownce

Random Wallpapers in Gnome

GNOME, Linux August 9th, 2008

There are many softwares in Windows(TM) which changes the wallpaper randomly from a given set of images. I was thinking of this for my Linux machine. I came up with a shell script. Though there can be many other ways. I just wanted to share my script and nothing else.

Update: There’s a tool which does all this automatically. drapes in Universe repository

Here in this code I am assuming that you have got all your wallpaper images in the directory /home/username/Pictures . You have to replace this directory with your wallpaper directory.

Here goes the code :

#! /bin/bash
wallpaper_folder=/home/username/Pictures
wallpaper_array=($wallpaper_folder/*.jpg)
number=${#wallpaper_array[*]}
((number=RANDOM%number))
random_wallpaper=${wallpaper_array[$number]}
gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$random_wallpaper"

Well, so let us quickly analyze the code. First line is the famous ’sha-bang’.

In the second line I am just setting the path of the wallpaper folder to the variable wallpaper_folder.

Third line I am creating an array containing all the file names with the extension jpg in the directory ‘wallpaper_folder’ (spaces are being escaped). More about bash arrays here.

Fourth line, I am calculating the number of elements in the array. This is the standard method of calculating the number of elements in a bash array. (replacing # with @ will also work fine).

Then in the fifth line, random number is generated within the range 0 to ‘number’. More about random numbers in bash here.

Sixth line set the variable random_wallpaper to the value corresponding to the key ‘number’ in the array wallpaper_array.

Seventh line, finally sets the file ‘random_wallpaper’ as the wallpaper. gconftool-2 is used to do customization in GNOME settings. Check out the man pages of gconftool-2 to know more about it. There’s a GUI tool for this gconftool-2 : gconf-editor

Now this script just sets the wallpaper randomly from a given set of images. Now you can schedule this script using cron to execute it at some regular interval. (In case you dont know what is cron, check out the manual pages of cron and crontab).

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • Facebook
  • TwitThis
  • Live
  • Technorati
  • Furl
  • Sphinn
  • blogmarks
  • LinkedIn
  • Pownce

VLC: Command Line Interface

Linux, vlc August 5th, 2008

This post is for those who love to work out everything from the terminal. Ever wondered how to play media files (audio or video) from the terminal ?? Check out !! First a screenshot :

vlc comman line

In this post I assume you are using Linux with VLC installed. VLC has a very simple GUI with lots of functionality. It also has an equally powerful command line ncurses interface. You can open this interface by typing in the terminal :

$ vlc -I ncurses

Now press ‘h’ to explore the help.

Let me show some usage. Say you have some mp3 files in ~/Music and you want to add all these mp3 files in playlist. You need to type in the terminal :

$ vlc -I ncurses ~/Music/*.mp3

And you will find all these files in the playlist.

There are a plenty of options like you can increase volume by pressing ‘a’ and decrease volume by ‘z’. For loads of other options press ‘h’ and browse through the help.

Keep rocking !

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • Facebook
  • TwitThis
  • Live
  • Technorati
  • Furl
  • Sphinn
  • blogmarks
  • LinkedIn
  • Pownce

A nice hidden feature of Firefox 3.0

Firefox August 4th, 2008

Firefox search bar is of great help. But the problem comes when one has to search in different search engines. say you have to search for IIT Guwahati in wikipedia. Now what you can do is search for IIT Guwahati in Google and then click the wikipedia link. Another option is directly go to www.wikipedia.com and search for IIT Guwahati. Yet another option is change the search engine to wikipedia in search tab of Firefox and then search for IIT Guwahati. Theres a very nice feature in Firefox 3.0 which gets you out of this situation.

Click the search tab in Firefox 3.0 and click “Manage Search Engines” . Then select Wikipedia in the list and then click “Edit Keyword” in the side panel and enter wiki in the text box that follows. Now close this “Manage Search Engine list” dialogue box.

Now in the address bar type in “wiki IIT Guwahati” , without Quotes ofcourse. Voilla! what you see is the Wikipedia article of IIT Guwahati. Similarly you can add keywords for other search engines and search directly from the Address bar.

I have added the keyword goo for Google, wiki for Wikipedia, yahoo for Yahoo!

Now I can easily search in multiple search engines.

Happy searching !

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • Facebook
  • TwitThis
  • Live
  • Technorati
  • Furl
  • Sphinn
  • blogmarks
  • LinkedIn
  • Pownce