Thursday, February 21, 2008

Python Scripts vs Bash Scripts in Linux

Almost all Linux users who are at least familiar with bash shell commands will be at home in writing simple bash scripts to automate tasks. For those who do not know how to write a bash script, here is how you do it.

Open a new file in your favorite text editor and save it in any name of your choice but with the extension .sh. For example, let us name it 'myfirstscript.sh' . The 'sh' file extension is not mandatory but is a nice way for us to later remember that this file is a script.

Now in this file (myfirstscript.sh), enter the following line.
#!/usr/bin/bash
This line should always be entered the first thing in any bash script you create. It lets the shell know where to find the bash program. In some Linux distributions the bash command is located at /bin/bash. When in doubt, use the 'which' command to find the location as follows :
$ which bash
/usr/bin/bash
# Continuation of the above script ...
# Now lets enter a few commands in this script ...
ls -l
sleep 2
who
sleep 2
w
Nothing spectacular here. Note that 'sleep' is used to pause the execution process for certain time in seconds. Next fire up a console (xterm, gnome-terminal ...) and set the executable bit for the script myfirstscript.sh as follows :
$ chmod u+x myfirstscript.sh
This lets you execute the script by its name as follows :
$ ./myfirstscript.sh
All this may seem easy. But you can get added benefits if you substitute 'bash' with Python language to write your scripts. Noah Gift provides compelling reasons to pick up Python programming language skills and start writing your scripts in this language. If you do not know Python language and is looking for some direction then you should look at the two books Core Python programming and Python phrasebook which will give you a head start in mastering this powerful but easy to learn language.

Cool AWN Applets to beautify your Ubuntu Linux Desktop

In the previous article, I explained how to install Avant Window Navigator in Ubuntu Linux (Gutsy Gibbon). By default, it doesn't install any applets. But a dock without any applets is as boring as a desktop without a dock right ?
So here are a couple of AWN applets which I found really interesting. But first the installation ...

Installation of Awn applets
To install these applets you have to enable an additional repository from reacocard. For that open the /etc/apt/sources.list file in your favorite editor and append the following line to it.
#FILE: /etc/apt/sources.list
deb http://ppa.launchpad.net/reacocard-awn/ubuntu gutsy main
Now update the repository and install the following package. NOTE: It is assumed that you have already installed the Avant Window Navigator.
$ sudo apt-get update
$ sudo apt-get install awn-core-applets-bzr
That is it. Now you can find all the applets in the awn manager which is accessed from GNOME Menu System>Preferences>Awn manager .


Fig 1: Awn manager GNOME menu

To run an applet, open the "Awn manager" dialog box and in its left pane, click the "Applets" icon. In the right pane, you will find all the applets installed on your system. Select an applet and click the "Activate button". The applet starts running on your Awn dock.

Fig 2: Awn manager GUI

A few cool AWN applets
Here are a couple of very nice applets which caught my fancy.

Dilbert Cartoon Applet - This applet displays comic strips of popular cartoon characters. At present you have a choice of 5 different strips namely - Dilbert, Peanuts, The born loser, Wizard of ID and Xkcd.com.

Fig 3: Dilbert applet displaying a comic strip
Main menu applet - This applet provides an alternate menu containing all the applications you will find in the menus on the GNOME panel.


Fig 4: Main menu applet - I find it more functional

Stack applet - I like this applet very much. It has three layouts namely "Default dialog", "Curved GUI" and "Trasher GUI". The "Trasher GUI" is the same as the "Default dialog" with the exception that in the former, there is a delete button embedded. The "Curved GUI" is what has picked my fancy and makes me think of the dock found in Mac OSX Leopard.
Fig 5: Click on the stack applet to open a stack of objects.

Terminal applet - What better way to use the dock than embedding a terminal into an applet ? The terminal supports transparency which makes it ultra cool. And you can even choose the terminal you want to embed such as gnome-terminal, konsole, xfce terminal, xterm and so on.
Fig 6: gnome-terminal embedded in the terminal applet


Fig 7: I am always interested in the weather :-)


Fig 8: The weather map of India
Get more of my blogs

Install Avant Window Navigator (AWN) in Ubuntu Linux

AWN - short for Avant Window Navigator is a dock like bar which sits at the bottom of the screen. It provides similar effects as the Dock in Mac OSX Leopard. The AWN project consists of three main parts namely
  1. The Dock
  2. AWN window navigator and
  3. The shared library 'libawn' which is used to develop applets which enhance the functionality of AWN. The applets can be coded in either 'C' or 'Python' language
Pre-requisites for installing AWN
To install AWN on your Linux machine, it has to meet certain conditions. Them being -
  • Xgl or AIGLX installed - in short your computer should be capable of compositing support. This mostly means if you have an Nvidia or ATI video card, you should download and install the proprietary drivers.
  • A compositing manager installed. A few examples of compositing managers are Beryl/Compiz/Compiz Fusion, Cairo, Xfce, Metacity, xcompmgr and so on.
    In Ubuntu you can enable compositing manager by clicking System>Preferences> Appearance and then enabling Visual effects from the 'Visual Effects' tab in the Appearance dialog.


Fig 1: Enable Visual effects
Installation
In Ubuntu Gutsy Gibbon, the installation of AWN is a two step process. First you have to enable the backports repository which contain the necessary binaries of avant window navigator and related files.
This is done by clicking System>Administration>Software sources on the GNOME panel.

Fig 2: Click on the Software Sources Menu
It opens the "Software sources" dialog box.

In that click the 'Updates' tab and enable the gutsy-backports option as shown in the figure below :
Fig 3: Enable gutsy-backports in the Updates tab
Next fire up a terminal and update and install the AWN packages as follows :
$ sudo apt-get update
$ sudo apt-get install avant-window-navigator awn-manager
awn-manager is a GUI tool which allows you to make changes to the look and feel of the AWN dock as well as install and manage applets and themes.

Fig 4: Avant Window Navigator close-up view

Now that you have installed Avant Window Manager, it is time to take it for a test drive. To start AWN, click GNOME menu Applications>Accessories>Avant Window Navigator.


Fig 5: Avant Window Manager menu


Fig 6: Ubuntu Gutsy Gibbon desktop running AWN


A few AWN tips:
  • To add applications to the AWN dock, just drag and drop icons from the Applications menu or from Nautilus (/usr/share/applications).
  • You can right click on the AWN dock and select properties to open the 'Avant Window Manager' dialog where you can change the look and feel of the dock and add additional applets.
Conclusion
Finally we Linux users have our very own dock similar to the dock seen in Mac OSX Leopard. While the AWN project is still a work in progress, there are a lot of applets available from the ubiquitous clock to the GMail checker which brings visual joy to the user's desktop. To know about these applets, read the following article.

Get more of my blogs.