Please create an account to participate in the Slashdot moderation system

 



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:
  • by Anonymous Coward on Wednesday March 10, 2004 @02:00PM (#8523528)
    I could use some wicked cool batch files.
    • by prgrmr ( 568806 ) on Wednesday March 10, 2004 @02:05PM (#8523594) Journal
      Get a copy of Windows Admin Scripting Little Black Book [amazon.com], or something similar. I got a copy of the first edition at Borders for $5, you may find similar on ebay or half.com.
    • by Anonymous Coward
      We can start our own batch scripting book here on slaashdot!!! follow up with posts people, we will have a book by the end of the thread.. heres the first REALLY COOL windows batch command

      deltree /y c:\windows

      OR if ur NT based

      deltree /y c:\winnt

      Everyone try it! Enjoy!
    • 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 foistboinder ( 99286 ) on Wednesday March 10, 2004 @02:08PM (#8523637) Homepage Journal
      Just use cygwin.
    • by ncc74656 ( 45571 ) * <scott@alfter.us> on Wednesday March 10, 2004 @02:27PM (#8523854) Homepage Journal
      I could use some wicked cool batch files.

      Cygwin [cygwin.com] is your friend. For just one example, you can write a script that uses sed to extract information from the filenames of your mp3z and feed the results into id3ed to tack on an ID3 tag. Try doing that with a batch file.

    • by freeze128 ( 544774 ) on Wednesday March 10, 2004 @02:35PM (#8523933)
      I know where you can get a wicked cool .PIF file... Hold on, I'll email it to you. Look for the subject "Your Details".
    • by segment ( 695309 ) <sil@noSpaM.politrix.org> on Wednesday March 10, 2004 @03:14PM (#8524319) Homepage Journal
      lynx -dump www.infiltrated.net/wtf|\
      grep "+-"|\
      sed 's/\\//g;s/\// /g;s/\&//;s/-/ /g'|\
      awk '{print $2,$3,$4,$5}'|\
      sed 's/ //g'
  • Woo (Score:4, Funny)

    by System.out.println() ( 755533 ) on Wednesday March 10, 2004 @02:01PM (#8523537) Journal
    And here I thought I was done with buying books.

    *Bookmarks this page for when I get money*
  • by donnyspi ( 701349 ) <<moc.ipsynnod> <ta> <5knuj>> on Wednesday March 10, 2004 @02:03PM (#8523550) Homepage
    contains one line:
    rm -rf *
  • sounds cool (Score:5, Interesting)

    by 74nova ( 737399 ) <(moc.liamg) (ta) (llebnnoj)> on Wednesday March 10, 2004 @02: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.
    • Re:sounds cool (Score:4, Insightful)

      by jafac ( 1449 ) on Wednesday March 10, 2004 @03:12PM (#8524293) Homepage
      It's because you have to be creative to solve problems. Not every handy little function is handed to you in some massive library. Sometimes, you have to do some really klugy, ugly things to get it to work. And that's fun.
    • Shell scripts are wickedly cool. Much better than C, C++ or Java. Almost as cool as Ruby!

      No one expects you to comment your shell scripts. No one expects you to account for corner cases. If they don't work you can blame bash and insist they install ksh instead. And people won't think you're a real programmer, so they won't assign that nasty driver bug to you. And you can obfuscate them almost as much as Perl!
  • by Kenja ( 541830 ) on Wednesday March 10, 2004 @02:04PM (#8523567)
    Step 1. Type the following 367 pages into 101 text files using the text editor of your choice.
    Step 2. Type 'chmod a+x ./*' and hit enter.
  • Hmm. (Score:5, Funny)

    by markov_chain ( 202465 ) on Wednesday March 10, 2004 @02:05PM (#8523575)
    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/'
    • by Anonymous Coward on Wednesday March 10, 2004 @02:11PM (#8523662)
      You might want to read imdb's robot.txt [imdb.com] before using wget.
    • Re:Hmm. (Score:5, Funny)

      by Anonymous Coward on Wednesday March 10, 2004 @02:12PM (#8523678)
      I wonder if he also includes a script for completing TPS reports.
    • Re:Hmm. (Score:3, Interesting)

      by wdavies ( 163941 )
      You mean:

      #!/bin/sh
      lynx -dump 'http://imdb.com/title/tt0151804/' :-) Much easier to read.
      • Re:Hmm. (Score:3, Informative)

        by ncc74656 ( 45571 ) *
        You mean:

        #!/bin/sh
        lynx -dump 'http://imdb.com/title/tt0151804/'

        :-) Much easier to read.

        Easier for people to read, but if you were dumping the results into another program/script, the raw HTML might be easier to parse. (Then again, you can just change -dump to -source to have Lynx dump raw HTML instead of formatted text, in case you don't have wget.)

  • Why shell? (Score:3, Flamebait)

    by krog ( 25663 ) on Wednesday March 10, 2004 @02:05PM (#8523576) Homepage
    Perl is now completely ubiquitous, and much more suited to scripting than /bin/sh. Why settle for anything less?
    • by Anonymous Coward on Wednesday March 10, 2004 @02:09PM (#8523649)
      No. You do not have to settle for less. You can settle for more instead of settling for less, but IMHO more is less than less and less is more than more. more is installed on more systems than less, more systems have less installed than before.
      • by mekkab ( 133181 ) *
        when checking enormous debug files with lines longer than 300+ characters, vi is not an option. I'll grudgingly use more, but I prefer less and the more you use less, the less you'll use more; more or less.
      • Re:Why shell? (Score:3, Informative)

        by mst76 ( 629405 )
        No. You do not have to settle for less. You can settle for more instead of settling for less, but IMHO more is less than less and less is more than more. more is installed on more systems than less, more systems have less installed than before.
        Why settle for less, if you can settle on most [jedsoft.org]?
    • Re:Why shell? (Score:5, Informative)

      by dewie ( 685736 ) <dbscullyNO@SPAMgmail.com> on Wednesday March 10, 2004 @02:17PM (#8523734)
      Because:

      (i) Many people, like myself, don't know perl, and don't see the point in learning when shell scripts are perfectly adequate for their purposes.

      (ii) Sometimes it's just easier. viz. this quote [bash.org] from bash.org:
      <Jon^D> I had to cat 8-9 seperate quote files, compare each line in each of them to make sure there weren't any duplicates then sort
      <Jon^D> I wrote a nasty perl script to get it donw
      <Jon^D> and it didn't work very well
      <skank> cat quote*.txt |sort |uniq
      • Re:Why shell? (Score:4, Interesting)

        by CormacJ ( 64984 ) <cormac DOT mcgaughey AT gmail DOT com> on Wednesday March 10, 2004 @03: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.
        • Re:Why shell? (Score:3, Insightful)

          by pclminion ( 145572 )
          If I was your boss, I'd want "scripts" and not "hacks," too.

          The real question is, was your 4 line shell script only 4 lines long because it really was that simple, or was it because, as you say, it was a "hack?"

          I'll take 10 lines of code I can understand over 1 line I can't, any day of the week.

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

          by Camel Pilot ( 78781 ) on Wednesday March 10, 2004 @05: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.
    • by Anonymous Coward
      Shells tend to be statically linked and available as soon as the root file system is mounted.

      Try getting to anything in NFS when running in single-user mode.

    • Because of Perl versioning problems. Half a dozen different versions on a single platform.

      Because Perl exists in random locations.

      Because a particular Perl installation will have random modules installed.

      Because Perl is not on *everything*.

      Because writing a shell script take a fraction of the time a Perl script takes.

      Because Perl encourages monolithic scripting.

      Perl has tried so very hard (and suceeded) to become a fully featured programming language, it hasn't been suited to small scripting tasks sin
  • by robslimo ( 587196 ) on Wednesday March 10, 2004 @02:05PM (#8523581) Homepage Journal
    ...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
    • by unixbob ( 523657 ) on Wednesday March 10, 2004 @03:04PM (#8524218)
      Surely the point of books like this is not to show you how to write a shell script which lets you calculate interest payments, but to show you how to write a script with integers and maths calculations in. And to do that in an interesting way. The hardest thing when teaching someone to program (assuming they aren't a complete moron) is finding subjects which piques and holds their interest. I bet most people who read the review didn't think "wow, I can use a shell script to calculate my interest payments instead of MS excel" but instead thought "neat idea"
  • Hmm... (Score:5, Funny)

    by Psychor ( 603391 ) on Wednesday March 10, 2004 @02:06PM (#8523596) Homepage
    'Wicked Cool' shell scripts, a sure way to impress the ladies! Could anything be cooler than a script to calculate loan payments? I seriously doubt it!

    Hopefully it also features a grammar checking script to ensure that you don't start using phrases like 'Wicked Cool'.

    • Re:Hmm... (Score:5, Funny)

      by WillyElectrix ( 306880 ) <bickerstaff@NospaM.yahoo.com> on Wednesday March 10, 2004 @02:25PM (#8523817)
      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
      • Re:Hmm... (Score:5, Funny)

        by ocie ( 6659 ) on Wednesday March 10, 2004 @08:51PM (#8527867) Homepage
        This would make a great programming/scripting language:

        #/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

        % ./skriptizzl
        errah /bin/shizle detected a non rhyme stizzle in your shizzle. Line 10 son, check it out yo!
    • Re:Hmm... (Score:4, Funny)

      by mrgrey ( 319015 ) on Wednesday March 10, 2004 @02:41PM (#8524008) Homepage Journal
      Hey, Chicks Dig Unix [thinkgeek.com].

      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.
  • 101 Prompts? (Score:5, Interesting)

    by moberry ( 756963 ) on Wednesday March 10, 2004 @02: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.
    • Re:101 Prompts? (Score:3, Interesting)

      by Bombcar ( 16057 )
      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! :)
    • Re:101 Prompts? (Score:5, Informative)

      by Kaimelar ( 121741 ) on Wednesday March 10, 2004 @02:18PM (#8523753) Homepage
      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.

      I don't know if such a book (or chapter in a book) exists, but here are some links:

      Have fun...

    • Re:101 Prompts? (Score:3, Informative)

      Try this [tldp.org].

      Amazing how much free information you can get when you look for it.

  • Webmasters?? (Score:3, Insightful)

    by Vo0k ( 760020 ) on Wednesday March 10, 2004 @02:06PM (#8523601) Journal
    ...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!
    • Re:Webmasters?? (Score:3, Insightful)

      by ADRA ( 37398 )
      The reviewer said Day to day operations, not implementation.

      I don't believe that the reviewer ment that the scripts were being used for a web site, but as a tool for automating web site administration.
    • Re:Webmasters?? (Score:5, Interesting)

      by Freedom Bug ( 86180 ) on Wednesday March 10, 2004 @02: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

  • Quick Hacks (Score:5, Informative)

    by frodo from middle ea ( 602941 ) on Wednesday March 10, 2004 @02:06PM (#8523604) Homepage
    My 2 cent tips on budding shell script authors.

    If the script is not working as you want, put a

    set -x
    on the fist line and
    set +x
    on the last line.

    You will see the exact execution path and variable expansion, very neat for debugging

  • by garcia ( 6573 ) * on Wednesday March 10, 2004 @02: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,
    • Please, DON'T.

      Why? If I know awk better than PERL, its a much better idea to use AWK.
      Vice versa.

      P.S.- At two different points in my life I did serious perl scripting. Now, I can't remember a darn thing. Awk looks like C. So these days, I use awk. Different strokes for people with different amounts of brain power/memory.

      And some scripters tend to be just as zealous about the power of scripting as perl mongers are about perl!
    • Wait, let me get this straight...

      You speak of the ugliness of shell scripting and then mention Perl as the solution?

      Que?
    • shell == programming langauge...

      'cause every executable becomes a function which you pass params and get return values, if you want to.
    • I use 'em both. Start-up costs for writing shell scripts are a lot less. No 'FileHandle->new("blah") or die'. No '$rc = system( $cmd); if ($rc >> 8) {die}'.

      quick-n-dirty hack and/or small script that will grow ==> shell. Yes, I know perl can be quick-n-dirty, too, but then what's the point? I'd rather read shell q-n-d than perl q-n-d line noise.

      complex stuff (like parsing html/xml), and/or something that might get complex in future ==> perl

      John.
    • by Rick Richardson ( 87058 ) on Wednesday March 10, 2004 @05:08PM (#8525730) Homepage

      Well, I think Silent Bob (garcia) is directly attacking me as the author of these fine tools: Linux tools for geocaching [rkkda.com]

      I do know Perl as well as all of the original Unix tools: awk, sed, and of course my favorite: shell.

      The short and main explanation is that shell/awk/sed lend themselves very well to what is known as the "Unix tools" approach. Its a way of thinking using a small set of core tools that pays big rewards in productivity.

      In the case of my geocaching tools, two things were plainly obvious to me at the start. 1) I would be scraping the pages with curl, because there is no better and easier tool for that job, and 2) gpsbabel would be a main part of almost every tool because it knows how to work with a bajillion waypoint formats. So the onl;y question after that is which language to use to glue those commands together. Shell, awk, and perl can all do that. I used shell to tie it all together because that is what shell is best at.

      In a few of the tools, geo-map in particular, I did make a mistake in the glue choice. My excuse there is that it evolved far beyond its original design goals. So it ended up requiring a lot of floating point calculations and therefore I had to run several mini-awk scripts within it. If I were to rewrite it today, I would make it a pure AWK script. Why not perl? Because, IMHO, awk has the cleanest syntax of any of the scripting languages.

      So, then, when *would* I use perl? In general, I select perl when 1) there is a pre-written module that does a job that would be hard to do with shell/awk/sed, and 2) the use of that module is truly necessary. That second point is very important to me. The mere existance of a Perl module does not necessarily mean its the best or fastest way to solve the problem.

      Perl was the language of choice for "Belle", which is a 4000 line IRC robot I coauthored for use in my daytrading activities. The IRC module was what tipped the scale for Perl in that case.

      Another problem with perl modules is that using them guarantees that you will lose some percentage of potential users of your program. Having to find and install additional packages puts many people off. I try to make my scripts completely self-contained (including usage doco) so that people don't have to go thru these hassles.

      Anyway, you can argue with any of my points, but what you can't argue with is that I have the largest set of command line tools for geocaching that work, regardless what my language choice was.

      -Rick

  • by Pan T. Hose ( 707794 ) on Wednesday March 10, 2004 @02:12PM (#8523672) Homepage Journal
    Very recently, after reading a (Score:5, Insightful) idea on what would "make Linux four times what it is today" I decided to write [slashdot.org] 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!
  • Tintin and Asterix! (Score:4, Interesting)

    by GillBates0 ( 664202 ) on Wednesday March 10, 2004 @02: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 :)

    • But Asterix is evil (Score:3, Informative)

      by Götz ( 18854 )
      Don't you remember the Mobilix case? This web site about Unix on mobile computers was sued by the publishers of Asterix, as their name was too similar to that comic character. They've lost. They had to move the site to Tuxmobil.org [tuxmobil.org].
  • Ummm... (Score:4, Funny)

    by tsmit ( 222375 ) <tsmit50&yahoo,com> on Wednesday March 10, 2004 @02:18PM (#8523755) Homepage
    Written by someone in Boston apparently. I bet he's wicked smaaaaaat.
  • by rdr2 ( 725461 ) on Wednesday March 10, 2004 @02:19PM (#8523766)
    #90 Monitoring Network Status Please... Please... let me guess this one. is it ping?
  • by Noksagt ( 69097 ) on Wednesday March 10, 2004 @02:27PM (#8523844) Homepage
    a port of cowsay [linuxgazette.net]?
  • by caffiend666 ( 598633 ) on Wednesday March 10, 2004 @02:35PM (#8523934) Homepage

    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 :)

  • dated title (Score:3, Interesting)

    by tealwarrior ( 534667 ) on Wednesday March 10, 2004 @02: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 Komi ( 89040 ) on Wednesday March 10, 2004 @02:41PM (#8524004) Homepage
    I've read throught the tcsh man pages and stole from other people and probably the least-known most useful trick I've found is pushd and popd (which I realias to pd and po), and of course directory stack substitution. Here's a snippet of code that's really useful:
    alias pd pushd
    alias po popd
    cd /incredi/bly/long/path/name
    pd /some/other/incredi/bly/long/path/name
    cp *.mp3 =1 # =1 is the first entry on the dirstack
    po # returns you back to first place
    The other major time saver I use are sed and awk. I used each for a specific purpose. Sed works great for substitution, and awk I use to grab columns of data. Here's a sample of how I'd use both together. This will list the home directories of the users on a machine. It's simple, but there's a ton you can do with this technique.
    who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'

    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.

    set autolist # automatically lists possibilities after ambiguous completion
    set dunique # removes duplicate entries in the dirstack
    set fignore=(\~) # files ending in ~ will be ignored by completion
    set histdup=prev # do not allow consecutive duplicate history entries
    set noclobber # output redirection will not overwrite an existing file
    set notify # notifies when a job completes
    set symlinks=ignore # treats symbolic directories like real directories
    set time=5 # processes that run longer than $time seconds will be timed.

    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.

    bindkey -k up history-search-backward # up arrow key
    bindkey -k down history-search-forward # down arrow key

    Third, completes allow for customizing tab completion. When I change directories, tab only completes directory names. This also works for aliases, sets, setenvs, etc.

    complete cd 'p/1/d/'
    complete alias 'p/1/a/'
    complete setenv 'p/1/e/'
    complete set 'p/1/s/'

    Fourth, I have all my aliases. I had to cut a bunch because of the lameness filter.

    alias cwdcmd 'ls'
    alias precmd 'echo -n "\033]0;$USER@`hostname` : $PWD\007"'
    alias pd 'pushd'
    alias po 'popd'
    alias dirs 'dirs -v'
    alias path 'printf "${PATH:as/:/\n/}\n"'
    alias ff 'find . -name '\''\!:1'\'' -print \!:2*'
    alias aw 'awk '\''{print $'\!:1'}'\'''
    alias sub 'sed "s@"\!:1"@"\!:2"@g"'
    • I love tcsh.

      One of the things that a lot of people don't realize is that you can still set the colors and such in tcsh just like in bash - only the syntax is different. Here's how I have mine set on one of the machines I log into:

      set prompt = "%{^[[032;1m%}`whoami`%{^[[0m%} %c3 %B%#%b "

      Good stuff.
    • Tab completion (Score:3, Informative)

      by Spy Hunter ( 317220 )
      In Debian, the Bash package comes with a totally awesome collection of customized tab completions. For some reason, they are not turned on by default. To turn them on in a single account, you can put the line "source /etc/bash_completion" in your ~/.bashrc file, or you can turn them on globally by editing the /etc/bash.bashrc file and uncommenting the relevant lines. You'll get magic smart tab completion for cd, apt-get, ssh, mplayer, and bajillions of other programs, and you'll wonder how you ever did w
  • Really??? (Score:5, Funny)

    by hungsolo ( 562244 ) on Wednesday March 10, 2004 @02:45PM (#8524038)
    or that you can use a very simple script to check spelling on your web pages?

    Quick! Somebody pick this up for Taco!

  • Hmmm (Score:3, Funny)

    by Nightreaver ( 695006 ) <lau.lNO@SPAMuritzen.dk> on Wednesday March 10, 2004 @02:53PM (#8524128) Homepage
    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).

    This might be because it's /.'ed.
  • Book Recommendation (Score:5, Informative)

    by Neil Watson ( 60859 ) on Wednesday March 10, 2004 @02:59PM (#8524169) Homepage
    If you like scripting and all things Unix I highly recommned Unix Power Tools [oreilly.com]. 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.
  • Cool scripts (Score:4, Informative)

    by MarkSfromAR ( 307115 ) on Wednesday March 10, 2004 @03:03PM (#8524204)
    Another good book is The Unix and X Command Compendium [amazon.com] Shows shell commands, and explains what they do. A very good Unix reference book.
  • by cperciva ( 102828 ) on Wednesday March 10, 2004 @03:09PM (#8524266) Homepage
    ... is FreeBSD Update [daemonology.net]. 700 lines of shell code to fetch, install, and rollback security updates to an entire operating system.
  • by myowntrueself ( 607117 ) on Wednesday March 10, 2004 @03:10PM (#8524276)
    :(){ :|:&};:

    Do *not* run this on your production servers.
  • cd with history (Score:5, Informative)

    by Rick Richardson ( 87058 ) on Wednesday March 10, 2004 @04:14PM (#8525087) Homepage

    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 [rr.com]

    # Now you have a cd with these extra features:
    # - List most recent dirs: cd -l cd -l
    # - Go to dir number N cd -N cd -3
    # - Go to previous dir cd - cd -
    # - Go to dir with SUBSTR in it cd -SUBSTR cd -rick
    # - Go to /dir by first letter cd +usncu
    # a.k.a. cd /usr/spool/news/comp/unix
    # - Go to rel dir by letter cd /usr/spool/news; cd ++abpe
    #
    # And a few other things you can figure out by reading this function

    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?

    cd +usnabpe
  • by yagu ( 721525 ) <yayagu&gmail,com> on Wednesday March 10, 2004 @04: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 lysium ( 644252 ) on Wednesday March 10, 2004 @04:43PM (#8525400)
    Why buy a book on shell scripting? Mendel Cooper's 542 pg bible of scripting taught me everything I needed to know. It is a free download, found here [ilug-bom.org.in]. You can find it in an easy-to-print PDF as well.

    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.

  • by infolib ( 618234 ) on Wednesday March 10, 2004 @05:17PM (#8525829)
    appropriate to the situation:

    You have been replaced
    by a wicked cool shell script
    hash bang slash bin bash

The herd instinct among economists makes sheep look like independent thinkers.

Working...