Wicked Cool Shell Scripts 569
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.
sounds cool (Score:5, Interesting)
101 Prompts? (Score:5, Interesting)
Re:What about us Windows users?! (Score:3, Interesting)
shell scripts vs. programming languages... (Score:5, Interesting)
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)
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)
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)
#!/bin/sh
lynx -dump 'http://imdb.com/title/tt0151804/'
Coulda done with this about 2-3 years ago... (Score:1, Interesting)
John
Re:Webmasters?? (Score:5, Interesting)
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)
Re:Don't start this argument!@ (Score:3, Interesting)
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)
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.
Re:What about us Windows users?! (Score:4, Interesting)
C:\> sh.exe myscript.sh
My personal favorite; (Score:5, Interesting)
Do *not* run this on your production servers.
Re:What about us Windows users?! (Score:2, Interesting)
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.
Re:What about us Windows users?! (Score:3, Interesting)
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)
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.
A little disappointed, actually (Score:2, Interesting)
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.
Re:the best shell script (Score:3, Interesting)
shell scripts still useful. (Score:3, Interesting)
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.
Re:Is there a shell script to... (Score:2, Interesting)
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.
Re:What about us Windows users?! (Score:2, Interesting)
Try GNU utilities for Win32 [sourceforge.net]
Forward as well as backward slashes in file paths are accepted.
Re:Why shell? (Score:4, Interesting)
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.
Re:shell scripts vs. programming languages... (Score:2, Interesting)
I think it's Perl vs Python (vs Ruby).
I HAVE NO IDEA WHAT THIS REGEX BULLSHIT MEANS (Score:3, Interesting)
But then I discovered The Regex Coach [weitz.de].
A couple I use everyday... (Score:3, Interesting)
this is my favourite bash function, psgrep()
ps aux | grep $1 | grep -v grepAnd my favourite script, cls:
#!/bin/sh
echo -e 'ESC[c'