Shell Scripting Recipes

Share this article

The command line is many things to many people. Some users run in horror, preferring a GUI for point and click administration. Others will not work anywhere but in the warm glow of the Bash Shell.

I live in both worlds, having found wonderful system administration solutions in the open source world, my favorite being Webmin. However, I continually return the the command shell for many of my tasks and scripting needs. This has become even more convenient in my case using Mac OS X as my OS, having the benefit of a world-class GUI and the underlying BSD Unix tools.

For some time I have considered myself quite adept on the command line. That was until Chris Johnson’s Shell Scripting Recipes (Apress) landed on my desk. Johnson was introduced to Unix and the shell in 1990, 5 years before I had that pleasure and has surely become a master.

Taking a step back – many of us who manage servers will use the shell for SFTP or SSH sessions, managing applications such as MySQL, mail servers, web servers and so on. Additionally, we frequently will write some useful scripts for exercises such as backing up data, replicating to other servers, checking logs and cleaning up caches and queues.

Johnson takes the shell to the next level, providing an extended look across utilities and functions capable of handling serious sophistication or even constructing applications to run on the command line, whether they are to be used for system administration or for some of our more advanced users or clients with technical staff managing their own domains.

Johnson starts appropriately with an introduction to the core functions and utilities available in the POSIX shell. This allows readers of his book to leverage this knowledge in today’s common shells, one way or another descendants of the POSIX shell. I did think the first chapter could have been more of an overview rather than diving right into an outline of Unix functions – which may be a stumbling block for brand new shell users. Though anyone with some command line experience should not have an issue getting into gear with the content.

Beyond the introduction, Shell Scripting Recipes gets serious, breaking down shell capabilities by functions – looking at manipulation of text files, dealing with strings, math functions, working with dates and more.

I found several chapters very beneficial to issues I deal with. First up was working with PATH (Chapter 7), which most of us have wrestled with building applications on Linux systems. Johnson’s provides three useful scripts (checkpath, addpath and rmpath) which allow an admin to deal with user paths. This can come in handy for those with clients running custom built apps on your servers.

Staying on the end user theme – I was thrilled to get introduced to pop3-funcs (Chapter 10). This introduces capabililities for troubleshooting pop mailboxes on many levels, from simple message and size counts to collecting message headers into an array for review or filtering manually from a technical support perspective. Additionally, Johnson covers pop3list, which acts like a pseudo email client in the shell. I found this an ideal tool for testing needs perhaps to verify delivery of messages to a client mailbox when rolling out a web app (or patching it) rather than configuring my own client to test a domain I will not use.

In Chapter 16, Johnson tunes into the world of HTML with some useful utilities I will make use of. I can think of many intranet and extranet uses for his mk-htmlindex, which indexes a directory of files without an index.html file and overrides Apache default settings. This allows one to format and control the header of the file while creating a directory listing. Not anything new, but I did also like Johnson’s text2html script, which converts text files to html. I have had many instances where I needed to convert numerous files to simple html. This may save me time compared to my normal process of loading the text files into a Dreamweaver and applying a template one by one.

In the end – Johnson has written a book that looks at the shell from several perspectives:

  • as a powerful utility for the command line user,
  • as an application environment for advanced users,
  • as a deep library of functions for system administrators.

There is likely something for every type of shell user in Shell Scripting Recipes, as a glance at the table of contents (PDF) should reflect.

Blane WarreneBlane Warrene
View Author
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week