Command Line Currency Converter For Linux

March 19, 2010 at 8:53 pm | LINUX | 8 comments

currency-convertMany times I prefer to just work from the shell. The ~/.bashrc file is a great place to put functions if you are using them regularly.

Let’s build a cool command line currency converter using google’s currency converter. You might require wget or curl and sed to do this.

Just run the following command in terminal.

wget -qO- "http://www.google.com/finance/converter?a=1&from=usd&to=inr&hl=es" |  sed '/res/!d;s/<[^>]*>//g';

This will convert 1 USD to INR (Indian Rupee).
Output:

1 USD = 45.4950 INR

What we are doing is, query google using wget and parse the output using sed.

You can use curl as well:

curl -s "http://www.google.com/finance/converter?a=1&from=usd&to=inr&hl=es" |  sed '/res/!d;s/<[^>]*>//g';

Isn’t that a long command. Lets create a cool bash function for the ease use:
Open you ~/.bashrc file in your favorite text editor and add the following lines and save.

currency_convert() {
  wget -qO- "http://www.google.com/finance/converter?a=$1&from=$2&to=$3&hl=es" |  sed '/res/!d;s/<[^>]*>//g';
}

Now Run:

$ currency_convert 10 usd inr
10 USD = 454.9500 INR

If you want to convert to more than one currencies at once, rewrite our function as bellow.

currency_convert() {
  for i in $3
  do
    wget -qO- "http://www.google.com/finance/converter?a=$1&from=$2&to=$i&hl=es" |  sed '/res/!d;s/<[^>]*>//g';
  done
}

Now run:

$ currency_convert 1 usd "inr gbp eur"
1 USD = 45.4950 INR
1 USD = 0.6603 GBP
1 USD = 0.7382 EUR

Happy currency converting :-)

Keep Track Of Configuration Changes Using etckeeper

March 16, 2010 at 8:57 pm | HOW-TOS, LINUX | 3 comments

The official etckeeper website says:

etckeeper is a collection of tools to let /etc be stored in a git, mercurial, darcs, or bzr repository. It hooks into apt (and other package managers including yum and pacman-g2) to automatically commit changes made to /etc during package upgrades. It tracks file metadata that revison control systems do not normally support, but that is important for /etc, such as the permissions of /etc/shadow. It’s quite modular and configurable, while also being simple to use if you understand the basics of working with revision control.

Install etckeeper:

Debian/Ubuntu users can install etckeeper and git using apt.

$ sudo apt-get install etckeeper git-core

Configure etckeeper:

Open /etc/etckeeper/etckeeper.conf in your favorite text editor. The first option that you need to look at is VCS, which is the version control system you want to use. By default it’s set to git, but you can change it to hg or bzr depending on your preference.

If you want to specify some git commit options look ‘GIT_COMMIT_OPTIONS’

Another option that you may want to look is AVOID_COMMIT_BEFORE_INSTALL. By default, etckeeper will automatically commit any pending changes when you install packages. You can disable it by setting AVOID_COMMIT_BEFORE_INSTALL to 1.

Also set AVOID_DAILY_AUTOCOMMITS to 1 for avoiding daily auto commit.

Using etckeeper:

Initialize etckeeper:

$ sudo etckeeper init
Initialized empty Git repository in /etc/.git/
$ sudo etckeeper commit -m "Initial import"

This will create a  git repository for /etc, add all files below /etc (except etckeeper ignore list) to that repository and commit (save) the current contents .

Whenever you make a coherent change to your configuration files, you can commit it by calling etckeeper commit:

$ sudo vi /etc/mysql/my.cnf
$ sudo etckeeper commit -m "mysql conf change"

You can view your commits(saves) using simple git commands:

$ cd /etc/
$ sudo git log

or use a git front-end to see the commits:

$ cd /etc/
$ sudo gitk

etckeeper

Do try it out!

Download And Convert Youtube Videos: The Linux Way

March 11, 2010 at 11:16 pm | LINUX | 1 comment

youtube

youtube-dl is a small command-line program to download videos from YouTube.com.

To Install youtube-dl do this:

$ sudo apt-get install youtube-dl

To download the flv video do this :

$ youtube-dl http://www.youtube.com/watch?v=siQgD9qOhRs -o video.flv

Use VLC Player or MPlayer or Kaffeine to play the flash video.

Convert youtube videos:

ffmpeg is a command line tool to convert one video file format to another.

To install ffmpeg do this:

$ sudo apt-get install ffmpeg

Convert flv to mpeg:

$ ffmpeg -i video.flv -ab 56 -ar 22050 -b 500 -s 320x240 video.mpg

-ab : Sets the audio bitrate. Without this, it’ll be set to the default of 64kbps

-ar : Sets the audio samplerate. Default is 44100hz

-b : Sets the video bitrate. Default is 2000kbps

-s : Sets the size. Default is 160×128px

Convert flv to avi:

$ ffmpeg -i video.flv video.avi

Convert flv to mp3:

The basic command:

$ ffmpeg -i video.flv audio.mp3

By default this will create a 64 kb/s file. You can declare the audio bitrate with -ab:

$ ffmpeg -i video.flv -ab 32k audio.mp3

If the flv already has mp3 audio, then there is no need to re-encode. You can just copy the audio stream. This will preserve the audio quality and will be much quicker since there is no re-encoding:

$ ffmpeg -i video.flv -acodec copy audio.mp3

Don’t know what the audio is? Just ask ffmpeg:

$ ffmpeg -i video.flv

Next Page »