Wicked Cool Shell Scripts
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.
I could use some wicked cool batch files.
And here I thought I was done with buying books.
*Bookmarks this page for when I get money*
I've got more mod points and GMail invi
contains one line:
rm -rf *
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.
use your turn signal! you people act like it's divulging information to the enemy
Step 1. Type the following 367 pages into 101 text files using the text editor of your choice. ./*' and hit enter.
Step 2. Type 'chmod a+x
"Have you ever thought about just turning off the TV, sitting down with your kids, and hitting them?"
did you know you could write a script to retrieve movie info from IMDb?
Please please tell me it's not
#!/bin/sh
wget 'http://imdb.com/title/tt0151804/'
Tsunami -- You can't bring a good wave down!
Perl is now completely ubiquitous, and much more suited to scripting than /bin/sh. Why settle for anything less?
Cretin - a powerful and flexible CD reencoder
...everything looks like a nail
Actually, I agree that shell scripting is a powerful tool and well worth understanding. But 'a loan calculator' script? Gee, once you know the formula, a coupla minutes in a spreadsheet will do the trick.
I guess all people, myself included, fall into the hammer/nail trap. I know C very well, so I use it for just about every little app. Hmm... maybe I oughta buy this book.
-RatOmeter
Hopefully it also features a grammar checking script to ensure that you don't start using phrases like 'Wicked Cool'.
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.
...webmasters will find this book fundamentally critical to day-to-day operations;
What webmaster uses SHELL scripts?!
I understand, PHP, Perl, some other CGI. Marginal use for scripts for log analysis, maybe some file management, making their own work a bit easier.
But shells were never meant to do any web work. They are too slow, too heavyweight, too vulnerable to abuse by malicious users to be used as server side extensions!
Anagram("United States of America") == "Dine out, taste a Mac, fries"
If the script is not working as you want, put a
on the fist line and on the last line.You will see the exact execution path and variable expansion, very neat for debugging
for the last time people, I am "frodo from middle eaRTH", not "middle eaST".
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,
You might want to read imdb's robot.txt before using wget.
Very recently, after reading a (Score:5, Insightful) idea on what would "make Linux four times what it is today" I decided to write a shell script which does exactly that. Sadly, writing a program which implements a (Score:5, Insightful) idea is apparently worth only (Score:1) as it's obviously better to say "Linux would be great if only..." than just doing it. Anyway, I have released it under the GNU General Public License. Enjoy!
Sincerely,
Pan Tarhei Hosé, PhD.
"Homo sum et cogito ergo odi profanum vulgus et libido."
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 and Asterix.
Note: I am in no way affiliated to these books/publishers/websites. I'm just an avid fan :)
An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
Written by someone in Boston apparently. I bet he's wicked smaaaaaat.
Yes, my girlfriend is a BitchX
#90 Monitoring Network Status Please... Please... let me guess this one. is it ping?
I haven't seen or read this book, but my first impression from reading the review is that it's just a book that lists some shell scripts. There's no real challenge. You could customize the scripts endlessly, but real hackers write the scripts themselves (okay, borrowing code sometimes)
So what? I just bought a cookbook on sauces. What's different? Maybe I like a little more garlic in most my sauces so I'll throw some in here and there. Most of the sauce recipes, i would have never have thought to go with something I usually eat. Why does there need to be a "challenge"? It simply makes my meal more enjoyable.
Having 101 shell scripts that I can tinker with and add things that I like, or use them in a way that makes using my computer more enjoyable is great!
I can hardly wait for: Wickity Wacked Scripts PHPhat Programs 101 Scripts With Bling Bling /bin/Shizzle Your Scripts
Sucka MC Unix Administration in a Nutshell
-w
Try getting to anything in NFS when running in single-user mode.
Is there a shell script included that makes it look like you are working? Isn't that the purpose of all good shell scripts?
Freedom is trouble :)
Here's to losing my Karma Bonus again....
"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.
In theory, there is no difference between theory and practice, in practice there is.
Here's other stuff I have grouped by sections in my .cshrc
First, I have my shell variables. The comments say what they do. The most important one is autolist.
Second, bindkeys are pretty neat. I rebind the up and down arrow keys. By default they scroll up and down one at a time through the history. You can bind them to search the history based on what you've typed so far.
Third, completes allow for customizing tab completion. When I change directories, tab only completes directory names. This also works for aliases, sets, setenvs, etc.
Fourth, I have all my aliases. I had to cut a bunch because of the lameness filter.
The ultimate goal of science is to unify all forces of nature to a single law that can be silk-screened onto a T-shirt.
Hey, Chicks Dig Unix.
Wore that shirt to my parents one time and my mom didn't exactly get it. Unix does not equal Eunuchs. Try explaining that to your mom.
-Tolerate my intolerance
Quick! Somebody pick this up for Taco!
The programming languages like C, C++, Java etc, are strongly typed languages and the compiler will give you sufficient information to correct your incorrect syntax problems.
So even when you switch from say C++ and Java, with a little common sense and reading the compiler errors and warnings you can easily pick up java syntax, keywords etc.
But with scripting languages it is not so, as they are not compiled. This is especially a headache when you are dealing with multiple unix machines having differnet shells.
I once worked at a job where I had to use , csh (c-shell) , sh (original bourn shell) , ksh ( korn shell ) and bash (bourn shell ) on different linux, solaris and HP-UX boxes. It was a real headache maintaining the scripts.
All these scripts differ quite a lot in syntax , especially for arethmatic, redirects , invoking sub shells , comparision operators etc.
What is needed is a good shell cross referencing manaul which will provide comparative features of at least the major shells like , bash , sh, ksh, csh, tcsh , zsh.
for the last time people, I am "frodo from middle eaRTH", not "middle eaST".
Yeah, and she only knew how to make a couple of kinds of sauce. Even a master chef needs a cookbook. Or a hundred.
The whole "real hackers do it themselves" argument is crap. No man is an island, and we all learn something from others. If someone wants to be an elite h4x0r d00d, does he have to be raised like a veal in front of a computer with nobody to tell him how to turn the fucking thing on?
The whole point of networks is to share knowledge. If you don't try to build and add to that knowledge, then you are a free rider, and you are land and annoying. If you take the knowledge you can find easily and extend it or use it in a new, fun, or productive way or in an unexpected context, then you are doing what, IMHO, "hacking" is all about.
Taking an elitist "I am uber h4x0r, and I did it all by myself!" attitude is alienating and contrary to my notion of what hacking should be about. It's also bullshit. Even Torvalds had help. Going the reductio ad absurdum route, if you didn't write your own OS, then you are just a lamer according the lone wolf hacker theory. JFC.
GF.
Lots of petrified grits
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).
/.'ed.
This might be because it's
If you like scripting and all things Unix I highly recommned Unix Power Tools. I bought a copy last month. All the things about Unix that could not necessarily fill an entire book other their own nicely packaged together.
UNIX/Linux Consulting
Another good book is The Unix and X Command Compendium Shows shell commands, and explains what they do. A very good Unix reference book.
It just doesn't do quite what you might expect if your only experience is Linux.
Government of the people, by corporate executives, for corporate profits.
:(){ :|:&};:
Do *not* run this on your production servers.
In the free world the media isn't government run; the government is media run.
Actually, we decided here ( a fairly large installation) long ago to merge / and /usr.
Our main reason was simplification and this allows us the benefit of not worrying what is in /usr/bin and what is in /bin. (Actually, on Solaris, /bin is just a link to /usr/bin ). Everything in /usr and
/ should not be touched anyhow except through the
normal pkg management tools. We do of course maintain a separate /usr/local.
The main disadvantage is that a fsck would take longer because / is now a large filesystems. With the journaled filesystems of today, we don't see the concern. The other benefit is that we don't need to worry about sizing / and /usr independantly and running out of space in /usr
when / still has lots (or vise versa).
Interestingly enough, /usr/openwin used to be a separate FS on SunOS long ago. The main reasoning was that disks back
then were small and you simply didn't have room to
place /usr/openwin in the /usr/ filesystem.
I would guess that others have merged /usr and /
too but I understand why it's a bit of a
controversial topic.
I do hold disregard for some of the defaults that some Linux distros use where /var and / are merged
as well. In fact, the whole darn OS is in /.
The need for a separate /var should never go away
IMO.
The shell helper that I am totally lost without is one that adds directory history to bash and ksh. You can find it here: _cd
I guess I never really got the idea of a stack of dirs being useful, since I seem to bounce around more at random than anything else. I prefer to have a cache of places I've recently been.
Bonus puzzle for slashdot readers: using the cd with history function, what directory is this command likely to take me to?
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.
From the site:
This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction (...all the while sneaking in little snippets of UNIX wisdom and lore). It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.
Together, we will drive the rats from the tundra.
The latest version of sh.exe is 465k bytes, it sounds like you have an old version. You should upgrade it. :)
But then I discovered The Regex Coach.
The trick with Windows is that you can do many of these same things, but this power comes from doing it in WSH or VB (or C/C++ or an ASP or whatever language you're comfortable with. I've even done it in Perl.) You use the COM interfaces of the shell object to enumerate through directory trees and files. You can stream each of those files into the COM interface of another program that accepts streams. You can search, you can pipe stuff all over, and you're not limited to a single instance of stdin, stdout and/or stderr.
It's not unlike shell scripting, it's just a different language. Each application is able to expose whatever it feels is most important in whatever fashion it thinks is best. DevStudio, for example, lets the scripting host user get to the workspace, the project, and any of the tools.
The biggest problem I have with it is that stdio is not "guaranteed" to be supported by every application under Windows. stdio is the glue that binds all the UNIX utilities together. That's the beauty of stdio -- as the sole mechanism for I/O for most tools, it became the defacto application interaction interface. Windows doesn't have that: most Windows apps don't offer any automated IO at all. And some of the ones that do seem to have interfaces pasted on after the fact. But the ones that do expose properties and methods via COM are easy to access, and easy to control from anywhere. And using the interfaces tends to remove the ambiguities: in UNIX if you're using 'cut' to parse a phone list but the name field sometimes contains commas, you end up hacking around solutions to make them work. A COM-based solution would provide an interface containing a Name field.
Windows is not alone in this limiation, either. UNIX suffers from a similar problem: how do you meaningfully pipe data to and from an X window, or even to a curses app? Is it consistent between apps? Most apps I am familiar with that offer such features in their applications had to have code added to actively support a meaningful commandline interface to their programs through the use of dozens of command line switches. Without this sort of code, using stdio to parse the output of a curses-based application becomes a tedium of screen scraping.
Don't get me wrong: I have a bevy of UNIX-like command line utilities for Windows, I use Cygwin and bash when I need to (although the file system mapping is worse than I could have imagined), and I will fire up a CMD script long before I think to write it as a VB or C++ program. I'm far more comfortable with the sh-style tools -- I grew up with them.
I'm not saying stdio is better or worse than using the COM interfaces of Windows; I'm just saying it's "different." And you certainly shouldn't be reinventing the wheel to script up utilities in Windows.
John
This would make a great programming/scripting language:
./skriptizzl /bin/shizle detected a non rhyme stizzle in your shizzle. Line 10 son, check it out yo!
#/bin/shizle -yo
#declare a gangsta (variable) called slim
I'm a big ass gangsta and my name is slim
#link in the math pimp (library)
math pimp is in tow and don't you fsck with him
#initialize slim to the hos (linked list) 4,3,2,1
# this causes an error because there is no rhyme
4 and 3 and 2 and 1 now slim and his hos be comming for you
#open a shoutout (file)
Yo, here's a shoutout to the users out there
hey Andy (CR LF)
hey Amy (CR LF)
hey Ben (CR LF)
hey Zack (CR LF)
#exit with no error code
peace out
%
errah
JET Program: see Japan, meet intere