Lockergnome    

  Syndicate This Newsletter  09.30.2003 GnomeREPORT

Well, I'm back from California, but if you ever travel you know that it takes a while to get fully caught up again! Unfortunately I was behind on a lot of things before I left, sometimes I feel like I'm trying to work under an elephant-sized load of deadlines, but I'll shovel my way out one way or another.

This backlog unfortunately does effect this newsletter. Rather than abandoning you folks to the high seas, I'm going to restructure how this newsletter is put together. That should help me get it out on time a lot easier - and at a good quality - without completely driving me mad as I try to keep up with everything I'm supposed to be doing!

So, the new plan is this. The EGGS, CHICKS, and PENGUINS sections will rotate, with only one of these available in each issue. The VOICE, CLICK, and MAN entries will stay in every issue. This should work a lot better than me having to cut all three down into tiny chunks (another restructuring option). Who wants to get just one paragraph per week on each topic??

Digitally Yours,              
Dee-Ann LeBlanc       


 GnomeEGGS

This week we have a guest EGG column. This article starts a short EGG series on shell scripting, so enjoy!

SHELL SCRIPTS 101
by

If you're following the travails of the Penguin by reading this newsletter, you're doubtless already exploring the nooks and crannies of Linux. If you haven't yet, you'll definitely want to pop open a Terminal window and explore the command line, because it's really only on the command line that you can see the remarkable power and capabilities of Linux.

For this tutorial, I'm going to step you through a simple, elegant, and darn useful shell script that'll save you from saying, "What CD was that file on?" It's a CD-ROM catalog utility. Let's jump in!

WORKING WITH CDROMS

Red Hat Linux, which is what I'm focusing on, offers the delightful capability of automounting CD-ROMs as they're inserted into your Linux system. They're actually mounted as /dev/cdrom on /mnt/cdrom, which means that you can use ls /mnt/cdrom to see what's on any inserted CD-ROM.

Taking that as a jumping-off point, it shouldn't be too hard to write a script that uses find to list all the files and directories on a disk and save it to a central database file. To find a file, then, just use grep to search the file. Reasonably straightforward, right?

The essential line of code is:

find /mnt/cdrom -print > $database

But, there are lots of nuances... first off, we need to have the script both index CD-ROMs and search for files in the CD-ROM list. That can be done by having searches require a pattern, but the script invoked without a pattern be a request to index a CD-ROM... IF it's mounted! How do you test for that? Using mount|grep, of course! If there's a disk mounted, you'll see this:

So we can grep for '/dev/cdrom' in the script:

There's a little bit of shell script magic going on here that's worth explaining, at least briefly. First off, we're doing the grep, but we don't want to see the results, just test the return code. It's zero (false) if there are no matches (e.g., there's no CD-ROM) and one (true) if there is a match. Since we're testing the inverse of that - execute the conditional statement if there isn't a CD-ROM mounted - we add "!" as a prefix. The output, therefore, should be discarded, as it is with the > /dev/null statement. In case there are errors, we also redirect the error output to /dev/null too, by mapping fileno 2 to fileno 1 (that's what the 2>&1 does). Later, we want the error message to go to stderr by convention, and that's done with a different redirect: >&2 sends stdout to stderr, as we'd like.

SMART AND LOGICAL TESTS

As with most decent shell scripts, it seems like cdcatalog actually has more tests than anything else. For example, what if the user invokes the script with more than one argument? Output an error:

What if the database isn't readable? Another error condition:

So let's look at the first chunk of the script in its entirety:

If a pattern is specified, ("$1" isn't a null string) and the database is readable (! -r $db means it's not readable), then grep for $1 in the database, ignoring case issues (the -i flag) and pipe the output through more in case there's a lot of it.

Assuming there's a database file built and updated, we're rockin:

... next time we'll look at the second block of code, the second that actually builds the database. Stay tuned!


Dave Taylor is founder of AnswerSquad and a long-time Unix and Linux expert. He's the author of a number of very popular books, including "Teach Yourself Unix in 24 Hours," "Teach Yourself Unix System Administration in 24 Hours," "Solaris for Dummies," and "Learning Unix for Mac OS X." In addition, he's just wrapping up a killer shell script programming book called "Wicked Cool Shell Scripts," coming in November/December. To keep up on his writing and learn about new publications, please join his info list at http://author-news.intuitive.com/.

Submit a Resource | Discuss | Recommend It!


 GnomeVOICE

I thought I'd throw in two interesting e-mails this week:

Sam writes:

"Just a note of correction in reference to the openproject entry in the last few lines of the last Penguin Shell issue:

"'If you get really stuck, start up X-Chat and log into irc.debian.org or irc.openprojects.net and join channel #debian. That is one busy chat room, with Debian Linux experts present 24/7, willing to help.'

"openprojects has long since been transformed into irc.freenode.net. If interested, and for more information on the change, you might drop by http://freenode.org/."

Jose writes:

"Hi. Thanks for the newsletter. I just wanted to point out that since Knoppix ver. 3.3 (9/22/03), there's a new script for a HDD install. Press Ctrl-Alt-F1 and then type knoppix-installer for the new HDD install script. Once installed on your hard drive, you can follow steps 14-16 of David McNab's tutorial and type apt-get update to obtain the latest update packages.

"The whole changelong for version 3.3 can be found at http://www.knoppix.net/forum/viewtopic.php?t=5017."

Submit a Resource | Discuss | Recommend It!


 GnomeCLICK

Stefan writes:

"I just discovered this interesting app: WiredX. WiredX.net enables access to Unix applications from Windows machines via web browsers.

"Requirements (according to the website):
"'To use WiredX, you need Windows 95/98/NT/2000, Internet Explorer or Netscape Navigator, Java2 Plug-in(v 1.3.* is preferable) and of course, Unix machines on your LAN for running x clients. If you use Gnome and KDE on the WiredX, a Celeron 400MHz, 64MB RAM machine is preferable.'"

Submit a Resource | Discuss | Recommend It!


 GnomeMAN

Tarrith Do'Urden writes:
"Love your page as it is very informative; just wondering if you could touch on a subject that is driving me a little batty at the moment.

"I have downloaded a copy of Clustermatic (I'm trying out clustering). It boots from the CD-ROM, but... at a particular point, it waits for a RARP request. I think I have an idea what a RARP is, but wouldn't have a clue how to get it working. Just thought you might."

Dee-Ann responds:

Ah, clustering. That's what I was teaching in California! To start with, type /sbin/arp at a command line. You'll get a response similar to:

ARP (Address Resolution Protocol) maps IP addresses to MAC addresses. A MAC address is a unique series of hexadecimal numbers that specifically identifies only one Ethernet card on the planet. This helps to make sure that the Internet doesn't descend into new levels of chaos where packets are bouncing around every which way trying to find where they belong.

Now, your problem is with RARP. That's just the reverse, where MACs are mapped to IPs. Most cluster installers at some point either need to be able to automatically learn what the MAC address is for each node using a network boot (something that isn't supported still in many modern BIOS's), or need you to tell them what MACs it's trying to talk to so it can use DHCP to then assign IP addresses to each node's Ethernet card.

You can find out if your nodes support network booting by rebooting them and seeing if you're offered more than one pre-BIOS option. For example, you might be told to press Del to enter Setup, or F12 to network boot. When a machine is network booted, it broadcasts its MAC among other things out onto the network. If your BIOS doesn't support network booting, then the most painful way to set up for netbooting is to place the netboot code onto a computer chip and then solder that chip onto your Ethernet cards. Frankly, that sounds like something to avoid when all possible.

Some cluster installers offer an option for creating a netboot floppy disk instead. However, these require you to first learn the MACs for each of your Ethernet cards and, typically, enter those into a file that you can then have the cluster installation routine load. You can use a lot of different techniques to, one by one, learn those MACs. A simple one is to use either a bootable Linux distribution such as Knoppix, or a rescue disk from a full Linux distribution such as Red Hat, in order to boot and access a shell where you can type /sbin/ifconfig -a and copy out the resulting MAC.

Hope this helps!

Ask Dee-Ann a question | Ask in the forums | Recommend It!


Cool Tools:
 GnomeDomains
 GnomePortable
 Gnomies.com
 GnomeSavings
 GnomePersonals
 GnomeJobs

Reading Materials:
 CPU Magazine
 Computing Guides
 Internet Business  PayPal Library
 HOT! Wi-Fi Help

HostRocket provides web hosting that is affordable, reliable, and full of features.

Current Content:
 Windows Daily
 Digital Media
 Tech Specialist
 Penguin Shell
 Apple Core
 Web Weekly
 Technology News
 File Of The Day
 RSS Resource
Search:

Our Community:
 Gnomedex Conference
 The Forums
 Live Chat Room
 Tell a Friend!
 Watch The Webcams
 About Lockergnome

Contact Us:
 General Feedback
 Sponsorships
 Submit a Link
 Ask a Question
 E-mail the Editor
 The Editor's Site

 


Past Issues:
Software:
Register a Domain:
Domain Transfers:
Hardware:
Amazon Products:

Get Listed Here

Question: which group is 250,000+ strong and always looking for stuff to make their personal and professional lives run smoother?

 

Get yourname@gnomies.com today

 


©1996-2003, Lockergnome LLC. ISSN: 1095-3965. All Rights Reserved. Please read our Terms of Service. Web site hosted by Webair. Domain registered at DNS Central. Powered by Lyris ListManager. Chris Pirillo fueled by Peet's Coffee. Headers provided by Habeas. Statistics provided by Urchin.