Tuesday, March 30, 2010

Site News: LinuxCommand.org Turns 10!

LinuxCommand.org is 10 years old!  The site first went live in March 2000.  Since then I've had about 3.2 million visitors (at least according to the statistics at SourceForge where I'm hosted), received many kind emails from my readers, written a book, distributed a lot of scripts, and been mirrored all around the world.

In the coming year, I hope to update the tutorials on the site.  Much of the text, believe it or not, dates back to the beginning of the site, another testament to the enduring value of learning the command line.  But even so, the tutorials are getting a little outdated and my own knowledge has grown considerably over the last ten years as well.

As you may have noticed, this blog has been pretty busy and I have settled into a routine of posting twice a week (on Tuesdays and Thursdays) and I have many more topics in mind to cover.  And there is always the book to improve.  I've even toyed with writing another one...

Anyway, I want to thank everyone for their kind words of encouragement and support.  I know I don't always respond to each email that I receive, but I do try.  Speaking of support, you can support the work here at LinuxCommand.org by purchasing your very own printed copy of my book.  I've donated money to a number of free and open source software projects over the years and continue to "pay for my software" by producing this site and performing software testing on projects that interest me.

Thanks to everyone for ten great years!

Further Reading

A look at LinuxCommand.org over the years, courtesy of the Wayback Machine:
The traffic history of LinuxCommand.org:

Thursday, March 25, 2010

byobu

One of the features I have discovered during my testing of the Ubuntu10.04 beta is a nifty program called byobu, a slick wrapper for the screen terminal multiplexing program.  If you are unfamiliar with screen, please see the final installment of my Building An All-Text Linux Workstation series.

byobu was introduced in Ubuntu 09.10 and continues in 10.04.  The name "byobu" comes from a Japanese word meaning "folding screen."  Essentially, byobu adds an improved user interface to screen and takes advantage some advanced features in recent screen versions.  On a system so equipped, you launch byobu like this:

bshotts@twin7:~$ byobu

and you get a display like this:



We get a screen terminal session with system status notifications at the bottom of the terminal display.

byobu allows the use of function keys in addition to the usual Ctrl-a sequences supported by screen.  As indicated at the bottom right corner of the terminal, the F9 key invokes a menu:



Function Key Assignments

byobu assigns function keys to perform many of the common operations performed by screen, such as opening new terminal sessions, moving from session to session, and entering scroll back mode.  Selecting the "Help" item on the menu displays a map of the program's function key assignments:



Status Notifications

Also of interest is the list of available system indicators which is visible when the "Toggle status notifications" item is selected on the menu:


As you can see this is a pretty big list.

Other Features

It's also possible to create default windows, that is, terminal sessions that appear automatically when you start byobu.  This is handy if you have several applications that you want to start when you log in at the terminal.

Further Reading
  • The screen and byobu man pages
byobu's home at Launchpad
A Wikipedia article on Japanese folding screens

Tuesday, March 23, 2010

Project: Getting Ready For Ubuntu 10.04 - Part 3

Now that Ubuntu 10.04 Beta 1 has been released, it's time to start our work.  In this installment we will obtain a copy of Beta 1, make some installation media, install it, and begin our testing.

Getting The Beta 1 Image

This page has links to the ISO images that we will use.  Of course, you could just download them from your web browser, but what's the fun in that?  Since we are command line junkies here at LinuxCommand.org, we use the command line to download our images.  You can do it like this:

me@linuxbox: ~$ wget url

where url is the web address of the ISO image we want to download  In my case, I used this command to get the "PC (Intel x86) Desktop CD":

wget http://releases.ubuntu.com/10.04/ubuntu-10.04-beta1-desktop-i386.iso


Creating Installation Media

The next step is making the installation media.  I always use re-writable media for this kind of work, so we have to first "blank" our CD, then write the image on it.  To do this, we use the wodim program.  First, we need to determine what our system calls the CD burner.  We can do this with the following command:

me@linuxbox: ~$ wodim --devices

wodim will execute and print a list of the optical media drives it sees.  The results will look like this:

wodim: Overview of accessible drives (1 found) :
-------------------------------------------------------------------------
 0  dev='/dev/scd0'    rwrw-- : 'Optiarc' 'DVD+-RW AD-7200S'
-------------------------------------------------------------------------

On my system, we see that the CD-ROM drive/burner is the device "/dev/scd0".  Yours may be different.

insert the re-writable disk into the drive.  If your system automatically mounts the disk, unmount it with a command such as this:

me@linuxbox: ~$ sudo umount /dev/scd0

Next, we blank the media with this command:

me@linuxbox: ~$ wodim -vv dev=/dev/scd0 blank=all

The blanking operation will take several minutes.  After it completes, we can write the image with this command:

me@linuxbox: ~$ wodim -v dev=/dev/scd0 -data ubuntu-10.04-beta1-desktop-i386.iso

After the write is completed, we need to verify that the disk matches the ISO file.  Using this command will do the trick:

me@linuxbox: ~$ md5sum ubuntu-10.04-beta1-desktop-i386.iso /dev/scd0
7ddbfbcfcc562bae2e160695ec820e39  ubuntu-10.04-beta1-desktop-i386.iso
7ddbfbcfcc562bae2e160695ec820e39  /dev/scd0

If the two checksums match, we have a good burn.

Installation

Depending on which variety of 10.04 you have downloaded (desktop, alternate, etc.), the installation procedure should be familiar to any Ubuntu user.  The live desktop version differs from previous versions in that it no longer prompts you for running live or installing immediately after booting, rather you are forced to wait (and wait...) for the entire live CD to come up before being prompted with a graphical screen.  Not an improvement, in my opinion.

After installation, the first thing we do is open a terminal and perform an update to the system using the following commands:

sudo apt-get update
sudo apt-get upgrade

Be aware that during the testing period, the Ubuntu team releases a steady stream of updates.  It is not unusual for a hundred or more package updates to be released each day during periods of heavy development.  I actually created this alias and put it in my .bashrc file on the test machine:

alias update='sudo apt-get update && sudo apt-get upgrade'

Now I just have to type "upgrade" to bring the machine up to date.

Paying For Your Software - Testing

This is a theme I have touched on before.  If you have been an avid Linux consumer, you should consider becoming an avid Linux producer.  Great software doesn't write itself.  There are many ways you can help build the future of computing (and by the way, cheer leading is not one of them).  One way is by performing good software testing.  I have included some links (below) that document some of the tools and techniques that Ubuntu recommend for testing and bug reporting.

Meanwhile, Back At The Ranch...

Work continues on cleaning up the production systems in preparation for the upgrade.  I also performed live CD tests on both systems to look for possible hardware incompatibilities.  I haven't found any on the desktop system (yet) and the laptop has some minor video issues when booting.  Work will continue.

Further Reading

10.04 Beta 1 Release Notes:

Some advice on CD/DVD burning:

Tips and techniques for software testers:
Other installments in this series: 1 2 3 4 4a 5

Thursday, March 18, 2010

Project: Building An All-Text Linux Workstation - Part 14

In this, our final installment, we will look at the screen terminal multiplexing program.  What the heck is a "terminal multiplexing program?"  I'm glad you asked.

Now that we have installed a bunch of interactive applications on our workstations and SSH to allow remote access, we have a slight problem.  Is it reasonable for an interactive program (like mutt) monopolize our terminal session?  Isn't Linux multi-tasking?  On the graphical desktop, we can have many applications running at once and, by moving the mouse, we can switch from application to application.  Of course, on the console, we can switch virtual terminals to provide multiple sessions and if we are using SSH, remotely accessing our workstation from a graphical desktop, we can open multiple terminal windows.

But there's another way.  The screen program allows multiple sessions inside a single terminal.  You can create any number of sessions and can even split screens to view two sessions at once.  Further (and this is the cool part), screen allows you to "detach" a session from a terminal and later re-attach the session to a different terminal.

Installing And Running screen

By this time, we all know the drill:

me@linuxbox:~$ sudo apt-get install screen

will install the screen package.  To run screen, we type screen at the prompt followed optionally by the name of a program we want to execute in the screen session.  If no program is specified, screen launches a shell.  Try this:

me@linuxbox:~$ screen top

After you run this command, top will execute and everything will appear normal.  However screen is now managing the terminal session.  screen recognizes a large number of commands.  You communicate with screen by pressing Ctrl-a followed by a command letter.  For example, to create another session type Ctrl-a c and a new shell prompt will appear.  There are now two sessions running in the same terminal.  We can cycle through the sessions by repeatedly typing Ctrl-a n (for next).

Listing Your Sessions

The Ctrl-a " command displays a list of your screen sessions:




From here you can use your up and down arrow keys to select a session to display.

Scrolling And Copying

If you are using screen on a terminal session displayed in a graphical terminal, you will notice that the normal scrolling mechanism no longer works.  This makes sense because if it did, your graphical terminal's scroll back buffer would contain the jumbled contents of all of the screen terminal sessions.  screen manages its own scroll back buffers, one for each screen session.  To access the scroll back buffer (which is called "copy mode" in the screen documentation), type: Ctrl-a [ and you will be able to use up arrow, PgUp, etc to navigate the buffer.  In this mode (which uses many of the vi keyboard sequences) you can copy text for later pasting.  You do this by marking text.  To mark text, you position the cursor  at the beginning of the text you want to copy and press the space bar, then move the cursor to the end of the text you want to copy and press the space bar again.  The marked region is copied into a paste buffer and screen exits copy mode.  To paste the copied text, type the screen command: Ctrl-a ]

Detaching And Reattaching Sessions

By far, the coolest feature of screen is its ability to detach and reattach terminal sessions.  Picture this scenario: you're at work and you have just started a long running job on your work computer in a terminal.  With screen, you can detach the session, log off, go home, reconnect with the your work computer, then reattach the still-running job to your new terminal session.

Here is a demonstration (assuming we have another computer besides our workstation, if not, you can use two virtual terminals on the workstation):

  1. Start screen on the workstation and create a few sessions and put applications in them.  Try top, mutt, and irssi, for example.
  2. After the applications are running, move over to your second computer and log into the workstation using SSH.
  3. On the second computer, enter the command screen -D -R into the remote SSH session.
  4. Poof!  All the screen sessions on the workstation are detached, you are logged off of the workstation console, and all of the sessions are reattached to the terminal running the SSH client on the second computer.  Pretty slick!

We've only touched on the capabilities of screen.  It has many commands and a configuration file that can be used to adjust many of its features.  See the links below for more detail.

In Conclusion

I hope you have enjoyed this series and that you continue to learn about the applications and techniques that we have covered.  While we created a workstation that did not have a windowing system, the programs we installed work just fine on graphical workstations too.  The text-based capabilities of Linux should never be overlooked.  Text-based applications are almost always faster and much less resource-intensive than their graphical counterparts, so they make great additions to you solutions toolbox.

Further Reading

The official GNU screen site and documentation:

A screen tutorial from the Debian project:

A quick reference guide to screen (this site also contains a lot of other well-written screen documentation):
Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Tuesday, March 16, 2010

Project: Getting Ready For Ubuntu 10.04 - Part 2

Last time, we announced our intention to upgrade some of our systems to Ubuntu 10.04, so what's next?  To paraphrase a sight gag from an early episode of South Park:


In this installment we are going to cover the planning phase of the upgrade process.  Good planning is often the difference between a good upgrade experience experience and a bad one.  As a computing environment becomes more complex, planning becomes more essential.  My environment is fairly complex so I have to plan.

Objective

The first element to any good plan (and not just for OS upgrades) is a clear objective.  That is, in the broadest terms,  what do we hope to accomplish?  In my case, I want to install Ubuntu 10.04 on two computers (my main desktop system and my laptop) currently running Ubuntu 8.04 while maintaining all of the application set (and capabilities), network integration, and user data.

Notice that I said install and not upgrade.  I have learned through many years of experience that upgrades don't really work.  They kind of work sometimes, but they never really work.  Often, an OS upgrade is not able to apply every new feature in the new version.  For example, converting an existing file system to a new file system type is often impossible.  Also, I don't want to reuse my existing configuration and settings files.  I want to reconfigure based on the new default configuration, again to take advantage of everything the new release has to offer.

I know (from scanning the forums) that a lot of people are content to just pop in an installation CD and push the upgrade button and hope for the best.  Then those same people start crying because they get a black screen when they reboot, or their wireless stops working, or their sound is busted, etc., etc., etc.

System Survey

Since our objective states that we have to maintain the application set, network integration and user data, we better figure out what that is.  We do that by performing an inventory of our existing system  Here are some things to keep an eye on:

  • Required Applications.  When performing your system survey, go through the application menus and list everything you rely on.  In an upcoming installment we will write a script that will prepare a package list to compare against the new installation to ensure that we reinstall all the apps that we care about.  If you use Firefox, pay special attention to bookmarks, stored passwords, and add-ons.
  • Network Services.  My workstations mount file systems on NFSv4 and Samba shares.  I also use an LDAP database to manage my address book.
  • Hardware Features.  We will want to make sure that all of our hardware is working.  During the testing phase we will cover video, sound, wired and wireless networking, CD/DVD reading and writing, printing, scanners/cameras, and USB devices

This is also a good time to do some system maintenance.  Between cleanings, computers get a lot of application and data buildup.  I have added many applications to my base system, some of which I use and others which I don't.  It's good to make a list and decide what you really want on your "new" computer and what you can live without.  The same goes for data.  Do you really need all those video files?  See if you can clear a few gigabytes off that disk.  It will make things easier later.

Testing

We're going to get involved with Ubuntu 10.04 starting with the Beta 1 release scheduled for release on March 18.  I have a test computer prepared where I will attempt to build approximations of the finished systems.  In doing so, I will be able to see what, if anything, blocks my desired configuration.  It also provides a chance to look at the new features in this release, as well as alternate applications.  We will also use live CDs to test the hardware support on the real systems.

Installation

Once the final release of Ubuntu 10.04 occurs on or about April 29, we should be ready to install.  We'll make our installation media, create and verify our final system backup, perform the installation, and restore any additional applications.

Configuration

The final phase of the project is adjusting the configuration of the new system to our liking.  This will involve recreating accounts and application settings.   We will also restore the user data from our backups.

After everything is restored and configured we will verify that everything is in order.  The very last step is to re-enable the system backups and begin using the systems for production use.

Further Reading

Other installments in this series: 1 2 3 4 4a 5

Thursday, March 11, 2010

Project: Building An All-Text Linux Workstation - Part 13

Don't touch that dial!  Even the most die hard GUI fans among you will enjoy this.

You may have noticed that throughout this series, I have posted screen shots of the applications used on our all-text Linux workstation; screen shots that obviously are taken from a graphical desktop, so what gives?  Am I lying about this being an all-text workstation?  Not at all.  I do take the screen shots on a graphical desktop.  How?  By logging in to the workstation remotely from another computer.

One of the great joys of Unix-like operating systems (such as Linux) is the way they work with networks.  Much of the Internet's technology was developed on Unix systems and it shows.  Ever wonder why URLs use forward slashes?  Unix pathnames!

Back in the early days of my Unix career (the mid-1990s), there was a idea going around (foisted by the marketing people at Microsoft) that the newly introduced Windows NT was going to rapidly "kill" Unix.  Real Unix people knew this to be patent nonsense (though many of their pointy-haired bosses did not) because NT lacked an essential feature.  It didn't support remote administration.  I remember system admins complaining bitterly about how to fix even simple problems on NT, they had to travel to the machine and work the graphical interface personally.  Meanwhile, my team and I were managing a national network consisting of hundreds of Unix workstations and servers from our little office.  The only time we ever had to travel to a site was to replace hardware.

Over the years, there have been several Unix technologies used to perform remote administration.  Today, the overwhelming favorite is SSH (Secure SHell).  SSH allows the creation of a secure encrypted tunnel between machines through which can flow any number of network protocols.  It's most common use however is simple command line access to a remote system.

It works like this: a local machine runs a SSH client program that talks to a remote machine running a SSH server.  Every Linux system I have ever used comes equipped with a SSH client but most distributions do not install the server by default.  This is unfortunate since almost every system can benefit from remote administration.

Installing The OpenSSH Server

The most popular SSH implementation in the Linux world comes from the OpenBSD project.  It's called OpenSSH.  It is usually broken into two packages: the openssh-client package and the openssh-server package.  The client package is usually installed by default but we will need to install the server package on our workstation.  We can do this with the following command:

me@linuxbox:~$ sudo apt-get install openssh-server

That's all there is to it.  After the package installs, the service will start and our workstation can now be remotely accessed.  To demonstrate, we will open a terminal window on another machine on our network and use the SSH client program (called ssh) to log into our workstation:

bshotts@twin2:~$ ssh me@linuxbox
The authenticity of host 'linuxbox (192.168.1.7)' can't be established.
RSA key fingerprint is bf:bb:0e:9b:af:a1:dd:e0:b6:44:48:79:97:2f:34:97.
Are you sure you want to continue connecting (yes/no)? yes

The ssh program is invoked with this syntax:

ssh [user@]hostname

where user is an optional user name and hostname is the network name (or IP address) of the machine we want to connect with.  If the user name is omitted, ssh defaults to the name you are currently using on the local system.

The first time you connect with a remote system, ssh warns you that it has never seen this remote machine before.  One of the security features of SSH is that it authenticates the remote systems you talk to.  This ensures that the machine you are talking to really is the machine you think it is.

After answering "yes" to the prompt, ssh adds the remote system to its list of remote hosts that it will recognize in future sessions:

Warning: Permanently added 'linuxbox' (RSA) to the list of known hosts.

Finally, it prompts you for the user's password on the remote system. 

me@linuxbox's password:


Once that is entered, you are logged in!



From here, you can use any of the applications on the workstation just as if you were sitting in front of the workstation's console.

To end a SSH session, use the exit command:

me@linuxbox"~$ exit
Connection to linuxbox closed.
bshotts@twin2:~$

Executing A Single Command On A Remote System

We can also use the ssh program to remotely execute a single command on our workstation.  For example, we could ask our workstation about its uptime and load:

bshotts@twin2:~$ ssh me@linuxbox uptime
me@linuxbox's password:
 13:58:39 up 2 min,  0 users,  load average: 0.10, 0.14, 0.06
bshotts@twin2:~$

If a command follows the hostname, ssh will execute the command on the remote system and the command's output is transferred to the local machine for display.

Copying Files Using SSH

In addition to the ssh program, the openssh-client package also provides two additional programs used for securely copying files to and from remote systems.  The first is scp (secure copy) which is used much like the regular cp command.  To copy a file named somefile.txt to the home directory of user me on the workstation, we would do this.

bshotts@twin2:~$ scp somefile.txt me@linuxbox:
me@linuxbox's password:
somefile.txt                                  100%   10     0.0KB/s   00:00

To place the file in a specific directory (and/or rename the file) on the remote system, follow the hostname with the pathname of the desired destination:

bshotts@twin2:~$ scp somefile.txt me@linuxbox:/user/local/share/shared_file.txt

The second file copying program is sftp (secure ftp) which is a version of the ftp program that uses SSH for transport.  Remember, the ordinary ftp program sends all of its data over the network unencrypted (including user names and passwords), making it unsuitable for use over the Internet.

Using The GUI With OpenSSH

The sftp protocol makes another feature possible.  Most graphical file managers support it.  From our graphical desktop we can move files to and from the remote workstation.  Here's how:

In GNOME, we go to Places -> Connect to Server...  and fill out the dialog as follows:





We will next be prompted for the password on the remote workstation:




After that, voila!  We're browsing the file system on the remote workstation:




Adding Additional Users

With the ability to remotely connect to our workstation, it would make sense to add some user accounts.  This way, more than one person can be using the workstation at the same time.  To add a user account for an imaginary user named "user1", we would do this:

me@linuxbox:~$ su -
Password:
linuxbox:~# adduser user1
Adding user `user1' ...
Adding new group `user1' (1001) ...
Adding new user `user1' (1001) with group `user1' ...
Creating home directory `/home/user1' ...
Copying files from `/etc/skel' ...

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Changing the user information for user1

Enter the new value, or press ENTER for the default
        Full Name []: Workstation User 1
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y

linuxbox:~# exit

logout
me@linuxbox:~$

Now user1 can log in to the workstation with the command:

ssh user1@linuxbox



Deleting A User Account

This command will remove the above user account, if desired:

deluser --remove-home user1

Invite Your Friends!

Next time you have your Linux buddies over with their laptops, surprise them with individual user accounts on your awesomely configured all-text workstation.  You'll be the hit of the party!

Further Reading

The man pages for ssh, scp, sftp

SSH is covered in The Linux Command Line (Chapter 17):

OpenSSH:

Windows users need not feel left out.  PuTTY is a popular SSH client for Windows:
Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Wednesday, March 10, 2010

Linux News: Ubuntu Is Making An Inroad On Servers

I read an interesting article in InfoWorld today about how Ubuntu is gaining market share in servers; a market long dominated by Red Hat.  You can see the article at:

http://www.infoworld.com/d/open-source/ubuntu-ready-run-your-business-servers-646?source=IFWNLE_nlt_openenterprise_2010-03-10

Tuesday, March 9, 2010

Project: Getting Ready For Ubuntu 10.04 - Part 1

As you have probably heard, the next release of Ubuntu, 10.04 ("Lucid Lynx") will occur during the final days of April 2010.  My production systems (the ones on which I do my writing and photography) are running Ubuntu 8.04 and I have decided to upgrade them to the upcoming version.  This is the first of five-part series that will document my transition to the new version.

The 10.04 version, like the earlier 8.04 and 6.06 releases, is a so-called LTS or Long Term Support version of Ubuntu.  This means that it receives security and bug fixes (but not application version upgrades) for a period of three years.  This differs from the usual eighteen month support period for ordinary Ubuntu releases.  I have used the LTS versions for several years and feel that it is the best choice for my production systems.  I use a lot of Linux distros in my work, but for the machines I must rely on, I choose stability over the latest features.  For example, my server systems are running CentOS 4 which first appeared in early 2005 and is still supported by Red Hat and the CentOS team.  In fact, the main reason I switched from Red Hat (Fedora) to Ubuntu for my desktop systems was the availability of the Long Term Support versions, a feature that Fedora does not offer.

The Opportunity

In a past life, I ran the QA department of a software company and I often employ these skills to perform software testing on new Linux releases.  This case will be no different.  The first beta release of 10.04 is scheduled for March 18 so we will begin our work then.  Testing is not just something I do for fun (it isn't) but it's important to look for problems that might interfere with the deployment.  By checking for problems now, we have a better chance of getting them fixed before the final release.

The Mission

Our mission is to upgrade the production systems while preserving the existing data and functionality of the current systems.  We'll also look for exciting new features and applications that will enhance their productive capacity.  We will probably do a little scripting and system administration along the way, too :-)

The Players

The two production systems involved are my Dell Inspiron 530N (which originally shipped with Ubuntu 8.04 factory installed) and my IBM ThinkPad T41 laptop.  We'll also use my main test computer, a Dell Dimension 2400N which is currently hosting our All-Text Linux Workstation.  We might also take a look at the 10.04 Netbook Remix version to see if it offers any compelling reasons for upgrading my two netbooks, which are now running 9.04 UNR.

Stay tuned.  This ought to be fun.

Further Reading

Other installments in this series: 1 2 3 4 4a 5

Wednesday, March 3, 2010

Project: Building An All-Text Linux Workstation - Part 12

In this installment, we're going to take a another look at messaging, this time focusing on Internet Relay Chat (IRC).

IRC is a popular text-mode application that finds wide use on a number of platforms.  Of most interest to us, is its use as a tech support tool.  IRC works by allowing a client program talk to a server that is part of an IRC network.  Multiple users connect to the server and organize conversational groups called channels.  Channels are topic-oriented and cater to a wide variety of interests.  The participants of a channel then can converse with one another via a scrolling text display.

The centerim program we recently installed supports IRC in addition to a number of other popular messaging protocols, however, in this installment we will install a dedicated IRC client called irssi.  To install irssi, we simply:

me@linuxbox:~$ sudo apt-get install irssi

To run irssi, we enter the command:

me@linuxbox:~$ irssi

and the initial screen will appear:



The first window displayed by irssi is called the status window.  It is used to display information about server connections and other status messages.  The initial message in the status message is useful as it points us to the program documentation and some specific connection instructions to join the Debian channel at Debian's own IRC server.

As you type, your input is displayed at the bottom of the screen.  Entries starting with a slash character are interpreted as IRC commands and everything else as a message to post.  To connect to the Debian server we type the following command:

/connect irc.debian.org



It will take a few seconds to connect.

By default, irssi will use your system user name as your "nick" or nickname during an IRC session.  It's possible that your user name will conflict with an existing name already registered by a user of that server.  In that case, we will get something like this:



To overcome this problem, we need to choose another nickname.  That is is done by entering this command:

/nick new_nickname

where new_nickname is the name you wish to use.  In the examples that follow, we will use the nickname "linuxbox", but you should make up your own.  We enter:

/nick linuxbox

and if we're successful, the status window will respond:

You're now known as linuxbox

Now that we have a connection to the IRC server, we next need to join a channel.  Channel names start with a the # symbol.  We can join the #debian channel by entering this command:

/join #debian

Next, we will see a list of all the members of the channel scroll by in another window which overlays the status window.



The prompt at the bottom of the screen changes to indicate that we are in a different window.  Within a window, we can use the PgUp and PgDn keys to scroll the window's contents and we can use the Ctrl-p (previous) and Ctrl-n (next) keys to cycle through the available windows.

As we observe the #debian window, it will slowly scroll as members post questions and answers.  If you are not familiar with IRC, you should consult a good tutorial and observe the general practices of the group before jumping in.  Most channels also post links to official guidelines for the channel's use.   You can see the guidelines for the #debian channel here.

To end our session, we enter this command:

/quit

Filtering Output

The default configuration of irssi displays a lot of non-message text in channel windows announcing the comings and goings of members:



To filter this out of a channel, you can use a command like this:

/ignore -channels #debian * JOINS PARTS QUITS NICKS

Saving Your Settings

As you go through the irssi documention, you will see that irssi has a lot of features and capabilities.  After you have changed your settings, such as adding the filter above, you can store your changes by entering the command:

/save

and your changes will be added to the ~/.irssi/config file.

Another Server To Try

Many Linux and FOSS projects have official support channels on Freenode.  You can reach the Freenode server at irc.freenode.net.  Try the #ubuntu, #fedora, etc. channels there.

Further Reading

IRC tutorials:

General IRC background:

Freenode:

irssi documentation:
Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Monday, March 1, 2010

dialog

Now that we have covered launching a script from the GUI, it's time to look at how to make our scripts a little more "graphical."  Interestingly, there are a number of tools that we can use to produce user interfaces for shell scripts.  In this installment, we will concentrate on the most mature of these tools, dialog.

The dialog program lets scripts display dialog boxes for user interaction.  It does this in a text-based manner, using the ncurses library.  It can produce a variety of user interface elements and can pass user input back to a script for processing.  The dialog package is not installed by default on most Linux distributions, but is readily available in most distribution repositories.

dialog has been around for a long time and has gone through a number of incarnations.  The current version (which is maintained by the Debian project) contains a number of features not found in earlier versions.

To demonstrate a few of the powers of dialog, we will write a script that displays a series of dialog boxes and provide some ideas of how to work with the output.  We'll start the script with the following code:


#!/bin/bash

# dialog-demo: script to demonstrate the dialog utility

BACKTITLE="Dialog Demonstration"

# message box

dialog  --title "Message Box" \
        --backtitle "$BACKTITLE" \
        --msgbox "This is a message box which simply\
        displays some text and an OK button." \
        9 50

The script invokes the dialog program with a series of options to set the title for the dialog box, the title for the background screen, the dialog box type (in this example a message box), the text to appear in the box and the size of the box (9 lines high by 50 characters wide).  When we run the script we get the following results:



Next we'll add the following code to the end of the script to generate another kind of dialog called a yes/no box.  In addition to the dialog box itself, we will also include some code to act on the results of the user's selection:

# yes/no box

dialog  --title "Yes/No Box" \
        --backtitle "$BACKTITLE" \
        --yesno "This is a yes/no box.  It has two buttons." \
        9 50

# examine the exit status and act on it
case $? in
        0)      dialog --title "Yes" \
                --backtitle "$BACKTITLE" \
                --msgbox "You answered \"Yes\"" \
                9 50
                ;;
        1)      dialog --title "No" \
                --backtitle "$BACKTITLE" \
                --msgbox "You answered \"No\"" \
                9 50
                ;;
        255)    dialog --title "Esc" \
                --backtitle "$BACKTITLE" \
                --msgbox "You pressed Esc" \
                9 50
                ;;
esac

The yes/no box offers the user three choices: yes, no, and a cancel which occurs if the Esc key is pressed.  To select a button, the user my use the Tab key to switch from button to button or, if dialog is being run inside a terminal emulator on a graphical desktop, the mouse may be used to select a button.

dialog communicates the user's choice back to the script via its exit status.  In the code that follows the yes/no box, we evaluate the exit status.  If the yes button is pressed, the exit status is 0, if the no button is pressed, the exit status is 1, and if Esc is pressed, the exit status is 255.




dialog can provide more than just simple button presses.  It can support edit boxes. forms, menus, file selectors. etc.  When returning more complex data, dialog outputs its results on standard error.  To demonstrate how this works, we will insert the following code near the beginning of the script (just after the BACKTITLE=... line) to define a function (read_tempfile) that will display the dialog output:


TEMPFILE=/tmp/dialog-demo.$$

read_tempfile() {

# display what is returned in the temp file

        local tempfile

        # read file contents then delete
        tempfile=$(cat $TEMPFILE)
        rm $TEMPFILE

        # message box to display contents
        dialog --title "Tempfile Contents" \
                --backtitle "$BACKTITLE" \
                --msgbox "The temp file contains: $tempfile" \
                0 0
}

Next, we will add the following code to the end of our script to display a menu box:

# menu

dialog --title "Menu" \
        --backtitle "$BACKTITLE" \
        --menu "This is a menu.  Please select one of the following:" \
        15 50 10 \
        1 "Item number 1" \
        2 "Item number 2" \
        3 "Item number 3" 2> $TEMPFILE

read_tempfile

This code displays a menu containing three items.  Each item consists of two elements; a "tag" which is returned when a choice is made and an "item string" which describes the menu selection.  In the example code above, we see that the first menu item has the tag "1" and the item string "Item number 1."  When we execute the code, dialog displays the following menu:



To capture and display the output of the menu, we redirect the standard error of dialog to the file named in the constant TEMPFILE.  The read_tempfile function assigns the contents of the temporary file to a variable (tempfile) and passes it to dialog to display in a message box.  After the menu is displayed and a selection is made by the user, the message box appears and displays the data returned to the script.

Next, we will add a checklist dialog by adding the following code to the end of the script.


# checklist

dialog --title "Checklist" \
        --backtitle "$BACKTITLE" \
        --checklist "This is a checklist.  Please from the following:" \
        15 50 10 \
        1 "Item number 1" off \
        2 "Item number 2" off \
        3 "Item number 3" off 2> $TEMPFILE

read_tempfile

As we can see, this code is almost the same as the code used to create the menu dialog.  The main difference is that the items in the checklist add a third field called "status."  The value of status may be either "on" or "off" and will determine if a selection is already selected or deselected when the program is run:




The user may select one or more checkbox items by pressing the space bar.

Next, we will add the following code to the end of the script to display a file selector
:

# file selector

dialog  --title "File Selector" \
        --backtitle "$BACKTITLE" \
        --fselect ~/ 10 30 2> $TEMPFILE

read_tempfile

For the file selector, dialog is passed the base directory for the selection (in this example the directory ~/) and the size of selector.  For this example we specify 10 files in the list and a 30 character wide dialog.




I think the file selector is easy to code, but awkward to use.  You move around the dialog with the Tab key and select directories and files with the space bar.

One of the more novel types of boxes provided by dialog is the "gauge" which displays a progress bar.  To try out this feature, we will add this code to the end of the script:


# gauge

# generate a stream of integers (percent) and pipe into dialog

percent=0

while (( percent < 101 )); do
        echo $percent
        sleep 1

        percent=$((percent + 10))
done | dialog --title "Gauge" \
        --backtitle "$BACKTITLE" \
        --gauge "This is a gauge.  It shows a progress bar." \
        0 0

The gauge dialog does not output anything, rather it accepts a stream of integers (representing the percent of completion) via standard input.  To provide this, we create a while loop to generate the stream of integers and pipe the results of the loop into dialog.  When the script runs, the stream of numbers causes the progress bar to advance:



Note too, that we specified the size of the dialog as 0 0.  When this is done, dialog attempts to auto-size the box to fit in the minimum necessary space.

Finally, we'll add another of the novel dialogs, a calendar:


# calendar

dialog  --title "Calendar" \
        --backtitle "$BACKTITLE" \
        --calendar "This is a calendar." \
        0 0 \
        0 0 0 2> $TEMPFILE

read_tempfile
The calendar dialog box is given a date in day month year format.  If the year is specified as zero, as it is in this example, the current date is used.  The user can then select a date and the date is returned to the script.




This concludes our brief look at dialog.  As you can imagine, dialog can be very handy for adding  improved user interfaces for those scripts that require it.  While we have covered its general themes, dialog has many more options and features.  Check out the documentation link below for the complete story.

Further Reading

Documentation for dialog:

Other dialog-like programs: