Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Unix Operating Systems Software Books Media Programming Book Reviews IT Technology

Wicked Cool Shell Scripts 569

norburym writes with a review of Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems. "This incredibly fun book (really!), written by Dave Taylor, a veteran UNIX, Solaris and Mac OS X author, is chock full of 101 scripts to customize the UNIX (Bourne) shell." Read on for the rest.
Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems
author Dave Taylor
pages 368
publisher No Starch Press
rating 10
reviewer Mary Norbury-Glaser
ISBN 1593270127
summary 101 Scripts for Linux, Mac OS X, and UNIX Systems

Chapters are divided into an array of topics sure to catch the attention of any UNIX based system user: The Missing Code Library, Improving on User Commands, Creating Utilities, Tweaking Unix, System Administration: Managing Users, System Administration: System Maintenance, Web and Internet Users, Webmaster Hacks, Web and Internet Administration, Internet Server Administration, Mac OS X Scripts, and Shell Script Fun and Games.

In true "cookbook" fashion, each hack is numbered and divided into The Code, How It Works, Running the Script, The Results and Hacking the Script. Throughout, the author clearly describes the syntax and functionality of each script, often with additional notes in How It Works detailing the syntax process and interesting asides. But Hacking the Script is what gives Wicked Cool Shell Scripts true value; where applicable, the author uses this section to describe script modifications to achieve a variety of alternative real world, practical results. This additional section alone easily triples the total number of scripts the reader is exposed to.

This book enables the reader to get "up close and personal" with their UNIX based system and explore the possibilities afforded by becoming intimate with the command line interface. The reader will find themselves easily propelled into the world of scripting, thanks entirely to Dave Taylor's ability to take what some might describe as a fairly dry topic and translate it into a logical and user friendly construct. Just reading through the table of contents is inspiring and intriguing; did you know you could write a script to retrieve movie info from IMDb? or track the value of your stock portfolio? or that you can use a very simple script to check spelling on your web pages?

Sysadmins and webmasters will find this book fundamentally critical to day-to-day operations; there are dozens of invaluable, customizable scripts highlighted in this book to enable professionals to save time and add simple, elegant solutions to annoying issues in their work environment. User account management, rotating log files, cron scripts, web page tweaks, apache passwords, synchronizing via ftp, etc. are all eminently useful and tweakable.

Geeky home users will discover they can use these scripts to work with files and directories, create spell-checking utilities, calculate loan payments, create summary listings of their iTunes libraries, and of course, play games. Many of the sysadmin scripts would also be of interest to the power user: analyzing disk usage, killing processes by name and backing up directories, to name a few. Both types of users will find this book inspiring and truly fun!

One of the secret pleasures of a technical book reviewer is finding those wonky bits of code that suffer from misplaced or missing punctuation, misspelled words and other basic typographic errors inherent in the book publishing process. I randomly selected many of these scripts to try out in the process of doing this review and...dang, haven't found any errata yet. But be sure to check out the errata page on Dave Taylor's web site for any that more astute readers may find (there were none, as of this writing).

Also be sure to take a closer look at Dave's shell script library, which lists additional scripts that didn't make the cut for the book. As convenient as it is to download the entire script library, I would like to stress the value of buying the book, which will provide you with invaluable instruction and guidance in understanding the syntax of the scripts and it also illustrates how making small but significant tweaks can modify the output to match your specific needs.

(A special nod of appreciation to Dave Taylor's Tintin references!)


You can purchase Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Wicked Cool Shell Scripts

Comments Filter:
  • sounds cool (Score:5, Interesting)

    by 74nova ( 737399 ) <jonnbell@gm[ ].com ['ail' in gap]> on Wednesday March 10, 2004 @03:04PM (#8523565) Homepage Journal
    i like shell scripting. i dont know why, it just seems more enjoyable than programming big apps in java or c++. maybe its just the size, they are done sooner. i use a script that upon booting writes the new IP on a dynamic IP machine to the httpd.conf file, i thought that was kinda cool. nothign complicated, just necessary.
  • 101 Prompts? (Score:5, Interesting)

    by moberry ( 756963 ) on Wednesday March 10, 2004 @03:06PM (#8523597)
    There needs to be a chapter on bash prompts. I have seen some slick prompts. Displaying; uptime, current directory size, time, battery power, etc. I'm pretty satisfied with a user@host:~, but i do like to put color in mine.
  • by josefcub ( 212738 ) on Wednesday March 10, 2004 @03:07PM (#8523616) Journal
    It's a little outdated, but Running MS-DOS [microsoft.com] by Van Wolverton, along with Supercharging MS-DOS [halfpricec...rbooks.com] by the same author not only contain basic DOS (and Windows) CLI tutorial information, but contain lots of batch-file examples, and uses for such batch files. I found them very handy learning MS-DOS (and nowadays, Windows) when I was younger.
  • by garcia ( 6573 ) * on Wednesday March 10, 2004 @03:07PM (#8523617)
    A guy I know that is into Geocaching likes to use archaic shell scripting to scrape web pages for information. While the scripts work they require other applications and quite a bit of messy code.

    Why would you use awk and sed along with a really ugly shell script to get something done when you could have just as easily used perl to acheive the same effect?

    Sometimes you should just use what is best for the job. I really don't think that using shell scripts to pull IMDB movie info is the best way to go.

    YMMV,
  • Re:101 Prompts? (Score:3, Interesting)

    by Bombcar ( 16057 ) <racbmob@bo[ ]ar.com ['mbc' in gap]> on Wednesday March 10, 2004 @03:13PM (#8523686) Homepage Journal
    I had a really bad-ass prompt for good old DOS 5 with ANSI.SYS support.

    It would save the current cursor position, write the date and time on the top line of the screen, jump back to where it had been, write the current directory, and do it all in nice colors!

    I do like Gentoo Linux's default prompt, which I've now copied to all my linux machines. Now if they'd just alias ls='ls --color' by default, I'd be real happy! :)
  • Tintin and Asterix! (Score:4, Interesting)

    by GillBates0 ( 664202 ) on Wednesday March 10, 2004 @03:15PM (#8523711) Homepage Journal
    A special nod of appreciation to Dave Taylor's Tintin references!

    And a special nod of appreciation to norburym for mentioning the Tintin references in the review!

    It was cool to see a reference to one of my favorite fiction/comic books on Slashdot. I hate to call Tintin and Asterix comic books because they're so much more than mere comics. I've noticed though, that not many people are as hooked to the Tintin and Asterix series in the US as in Europe/Asia. They're great for kids and much *much* better than the shitload of comics that they read nowadays.

    I've had trouble finding them in the public libraries (in 3 states) and even the big book stores. So people who haven't heard/read these books, are definetly missing out on some cool reading. Check them out at your local library or atleast their websites: Tintin [tintin.be] and Asterix [asterix.tm.fr].

    Note: I am in no way affiliated to these books/publishers/websites. I'm just an avid fan :)

  • Re:Hmm. (Score:3, Interesting)

    by wdavies ( 163941 ) on Wednesday March 10, 2004 @03:18PM (#8523744) Homepage
    You mean:

    #!/bin/sh
    lynx -dump 'http://imdb.com/title/tt0151804/' :-) Much easier to read.
  • by Anonymous Coward on Wednesday March 10, 2004 @03:18PM (#8523759)
    Bash scripts used to drive me up the wall back then. Now I've found the glory of Perl. Couple that with O'Reillys Learning Perl, Programming Perl and Perl Cookbook and you can say goodbye to bash forever... unless Perl use is prohibited *sigh*.

    John
  • Re:Webmasters?? (Score:5, Interesting)

    by Freedom Bug ( 86180 ) on Wednesday March 10, 2004 @03:19PM (#8523770) Homepage
    What webmaster uses SHELL scripts?!


    Um, me.


    My web server has 6 megs of RAM. (it's an embedded device). That gives me two choices: C or sh. Obviously sh doesn't work for everything, but it's sure a heck of a lot nicer than using C for the non-critical stuff.


    Ironically, I usually use Python for administration type tasks during development on real computers, and sh for the web sites themselves on the embedded servers.


    Bryan

  • dated title (Score:3, Interesting)

    by tealwarrior ( 534667 ) on Wednesday March 10, 2004 @03:38PM (#8523970)
    "Wicked Cool" seems like a pretty dated term to me but after all it is a book on shell scripts. Perhaps we'll see "Hella Cool Perl Scripts" next. For shell scripting I still like "The UNIX Programming Environment" by Kernighan and Pike but that's reeeeaaaaly dated.
  • by mekkab ( 133181 ) * on Wednesday March 10, 2004 @04:05PM (#8524226) Homepage Journal
    cat blahlblahblha.txt | awk '{ print $8 $2;}'

    just to give you an example. I like that both Perl and awk give you associative arrays for free.

    The last time I needed to analyze network usage per processor per second I wrote an awk script.

    I find it hard to believe that someone who actually knew perl would go back to using awk.

    Believe it. Its just what I do now.
  • Re:Why shell? (Score:4, Interesting)

    by CormacJ ( 64984 ) <cormac@mcgaughey.gmail@com> on Wednesday March 10, 2004 @04:05PM (#8524231) Homepage Journal
    I tend to agree. My boss is a perl nut. If its a system admin script, he wants it in perl.

    Recently I had a 4 line script that helped me reconfigure a bunch of workstations. He wanted in redone in perl, so a 4 line hack became a 50 line perl script.
  • by Ark42 ( 522144 ) <slashdot@@@morpheussoftware...net> on Wednesday March 10, 2004 @04:08PM (#8524254) Homepage
    Somewhere I found a standalone sh.exe that is only 344K and can be run from the command line just like:
    C:\> sh.exe myscript.sh
  • by myowntrueself ( 607117 ) on Wednesday March 10, 2004 @04:10PM (#8524276)
    :(){ :|:&};:

    Do *not* run this on your production servers.
  • by sharkdba ( 625280 ) on Wednesday March 10, 2004 @04:10PM (#8524279) Journal
    Just use cygwin.

    Someone educate me: why is this considered funny? Cygwin emulates *nix pretty well, most of the bash commands/utilities are part of it (if you chose to install them), so it's a good playing ground for bash scripts within Windows.
  • by Anonymous Coward on Wednesday March 10, 2004 @04:21PM (#8524431)
    Exactly. What makes shell scripts so much better on Unix isn't really the shell, it's the flexibility of the programs that come with a Unix.

    Take the DELETE command. It has trouble deleting multiple files at a time. It can't delete directories. Then look at Unix rm. It's easy to see why batch files are a joke.

    The shell itself is definitely more flexible overall, though. Definitely more scriptable. The Bourne way of doing conditions, loops, pipes and whatnot are definitely more intuitive, more flexible, and carry less baggage than command.com or cmd.exe.

    Fact is, Windows's shell has its roots in the idea of a single-tasking, interactive shell, with a user typing at it. Most of the "scripting" features seem to be tacked on later. Obviously, today it runs on a full multi-tasking OS, but the shell itself has yet to really catch up with that idea. (Did they implement job control yet?)
  • Re:Why shell? (Score:5, Interesting)

    by Camel Pilot ( 78781 ) on Wednesday March 10, 2004 @04:38PM (#8524635) Homepage Journal
    Well yes obviously perl would have to be in /bin, but I don't see what is wrong or difficult with that? I just looked and bash is over 600k so it is not like it is lightwieght or anything.

    Libraries other than the standard set of libraries are not be required for doing the simple tasks that shell scripts often do. I am sure the entire functionality of bash is well within the core of Perl.

    It's easy to have readable, reliable shell scripts with scoping, it's just not something you are used to doing apparently.

    No I admit I do very little in shell scripting mainly because I do not see the need. Perl supports many many features that ease program and script development.

    Also perl has builtins like open, readdir, socket, etc. In shell programming would you not have to do things like `cat file` to read file? Does this not increase the overhead of shell scripts by forking another shell?

    Eventhough my original post was mod'd flamebait it is not just a curious enquiry.

  • by himself ( 66589 ) on Wednesday March 10, 2004 @05:17PM (#8525124)
    I ordered this book thinking that it'd be a beefy tome a la "UNIX Power Tools" but it's a little lighter weight -- both intellectually and literally.
    Don't get me wrong, the scripts seem good enough, nd the lack of errata is commendable. But I don't want a loan calculator, weather tracker, or datebook: those seem like _applications_ to me, not scripts for system administration (as the book claims it contains).
    Anyway, I'll try some of them out on my iMac and my Solaris systems, but this won't be making that big move out of the bookshelf onto the desk, if you know what I mean.
  • by Anonymous Coward on Wednesday March 10, 2004 @05:25PM (#8525218)
    A cool way to avoid accidentally doing an rm -rf * in a directory is to create a file called -i in the directory. -i comes alphabetically before most other stuff so it acts as a parameter to rm and it prompts you before deleting each file.
  • by yagu ( 721525 ) <{yayagu} {at} {gmail.com}> on Wednesday March 10, 2004 @05:31PM (#8525288) Journal

    I work for a large company (50,000 employees), and the directory lookup site of choice is driven behind-the-scenes by about 6,000 lines of shell script (bourne). Having written this application, one of the most common back-handed compliments I get is when users ask what I did to optimize this application to make it SO FAST! I just smile.

    (btw, this lookup tool does more than simple fill-in-the-blank lookups -- it has a first-name-alias lookaside table (so I can find "Sue", even though she's in the database as "Susan", it is case insensitive (yawn), order insenstive, field insensitive (there's only ONE input box), and more than returning just the phone number of the employee, it draws the entire hierarchy around the employee (direct reports, peers, management chain). And, there are buttons for each person on the page to: send page; send e-mail; generate and org chart..., and much much more)

    Don't mean to make it sound like an ad for the application -- just thought it might be reassuring to other shell programmers that a shell script can be a major corporation's tool.

  • by jwpacker ( 711685 ) on Wednesday March 10, 2004 @05:49PM (#8525486)

    It may not be one that makes it look like you're working, but I did one once that made it look like the computer was...

    Y'see, back when I worked at IBM, we were all chomping at the bit to get Windows off of our Thinkpads. We had them dual-booting, for those times when we couldn't do what we needed to do in a hacked wine/lotus notes window, but spent most of our time in Linux, where a terminal emulator and a web browser were the only tools we really used very often.

    From on high came a directive that every workstation in the department must be running an antivirus. Immediately. They were auditing systems to ensure that the antivirus was running, and that the virus definitions were up to date. No amount of explanation would get through to them that Linux was relatively safe from viruses, and that there was no version of Norton for us to run.

    Finally, to get past it all, I hacked together a script in a few seconds that echoed information onto the screen at login time that made it look like there was an antivirus running, that it was checking and downloading the 'lastest virus definition file' and that it was finding no problems with the system.

    End of auditing problems.

  • by tootlemonde ( 579170 ) on Wednesday March 10, 2004 @06:16PM (#8525814)

    Try GNU utilities for Win32 [sourceforge.net]

    Forward as well as backward slashes in file paths are accepted.

  • Re:Why shell? (Score:4, Interesting)

    by Camel Pilot ( 78781 ) on Wednesday March 10, 2004 @06:21PM (#8525873) Homepage Journal
    O.K. I will call your bluff!

    Show me a shell script that takes more lines of code to do the same job in Perl. Perl has many more features like grep, map, hashes, , symbolic references, etc. that make short work of simple tasks that do not exist in shell.

    More likely the reduction of lines of code would be converting from shell to perl.

    I bet your boss know shell and Perl and has (in my humble opinion) make the right choice in standardization.

    I would recommend that you spend a little time with Perl (or python or ruby) and bet you would change your mind in short time.
  • (I have a sneaking suspicion that Perl vs. BASH is becoming the new emacs vs. vi.)

    I think it's Perl vs Python (vs Ruby).

  • by chemstar ( 457943 ) on Wednesday March 10, 2004 @07:00PM (#8526301) Homepage


    But then I discovered The Regex Coach [weitz.de].
  • by ewe2 ( 47163 ) <ewetoo@gmail . c om> on Wednesday March 10, 2004 @10:50PM (#8528257) Homepage Journal

    this is my favourite bash function, psgrep()

    ps aux | grep $1 | grep -v grep

    And my favourite script, cls:

    #!/bin/sh
    echo -e 'ESC[c'

All seems condemned in the long run to approximate a state akin to Gaussian noise. -- James Martin

Working...