Showing posts with label cross reference. Show all posts
Showing posts with label cross reference. Show all posts

Thursday, August 28, 2008

Online Encyclopedia Shell Script For Linux And Unix

Hey There,

Today's Linux/Unix bash shell script is a follow up (and the finishing touch, I hope ;) to a whole slew of scripts we've written to mine the knowledge on tap at reference.com. If you missed any of the others, you can still find them in our older bash script posts to access the online Thesaurus and, of course, the online dictionary. This time we're breaking the chains and losing the albatross by finally attacking (with some level of precision) the Online Encyclopedia and producing a shell script does it as much justice as we could muster.

Note added after initial post: Forgot to include the Online Language Translation Script. It fits in with this bunch fairly well :)

One of the major differences you'll note between this script and the others is that we've included a "pager" variable. If you've ever checked out the reference.com Online Encyclopedia you're aware that the average return on a query is substantially larger than what you get back from a typical dictionary definition or thesaurus synonym query (not to mention the size of your terminal window). The screen shots we have for you, below, were the result of painstaking effort trying to find a word or phrase that didn't have an exceedingly long and thorough write-up. We chose "/usr/bin/more" as the pager for this script, but it can be easily changed to "/usr/bin/less," or whatever your favorite pager program happens to be.

After toying with this project for a while, trying to figure out why some pages worked, some didn't and where in the good Lord's name any consistent marker could be found to create consistent output, I've actually kind of gotten into using it. Now, if I'm at my terminal "working my fingers to the bone ;) " I can just type:

host # ./ency.sh engelbert humperdinck

and try to figure out what my generation "doesn't" see in him ;) ...apologies to die-hard fans.

Like our previous scripts, this script uses wget and sed. This script was also an attempt at "brute force scripting" (just writing it as we think it), but it ended up being so aggravating trying to find the right mix of regular expressions to get back decent results for the broadest amount of queries, that I think the method can, now, only be referred to as "blunt force scripting" (that's our new term for scripting as if you'd just been hit in the head with a brick ;). There are a few places the script could be tightened-up, but, to be perfectly honest with you, we're scared to death of changing anything about it right now. Maybe later, when we've steeled our nerves ;)

Below are a few screen shots of the script's output. The first is for an actual "one-pager" on a query for a pretty decent novel named Glamorama and the other is what you can expect to see when your query returns the equivalent of 15 leatherbound volumes of text on a query for Robert DeNiro. The last, just shows common error messages we generated on purpose.

Possibly interesting fact: If anyone out there is having an 80's moment and vaguely recalls Toni Basil ("oh, Mickey, you're so fine, you're so fine, you blow my mind..." why do I know the lyrics? ;), you'd be surprised to know that even "her" entry spanned multiple pages. I was actually surprised to find that she's also an actress and starred with Jack Nicholson in Five Easy Pieces under the very same name.

Click on the captures below to see them all in IMAX:

Glamorama Encyclopedia Entry

Robert De Niro Encyclopedia Entry

Encyclopedia Shell Script Errors

As one last bit of explanation. There are 2 specific error conditions that we ended up throwing in here. One is pretty obvious, involving No Results being found. The other had me going for a little while, since I was positive that a query on "linux" must have some return, since a query for "unix" did. It turns out that, when the Online Encyclopedia returns way too many results (I believe around 752 for "linux") it will state that it found a whole ton of results and is only going to show you one. The glitch in the program here is that, at some large number, it says that but then doesn't return an actual entry. I ended up noticing this when I finally broke down and parsed the HTML return and saw nothing, followed by a visit to the website via browser where I noticed the condition. You can see what I'm talking about right here, unless they've fixed it already (or it only happens intermittently). In any event, we wrote a check so that, if there are a large number of results, and it does return one, you'll still get it, but you'll get a self-explanatory error message if you hit this bug. Not that it needs to be said, but every query returns more than one result (insofar as our field-testing has gone), and the default behaviour of the site is to only return the top "one" and include links to the others.

Hope you enjoy this script, and can find some use for it. Any suggestions for improvement would be greatly appreciated. Be forewarned; there is the possibility that some of your queries may come back with extra parts added on that we didn't catch (usually tacked on to the end... phew), which could also make the output look horrible. This is the best we've got "for now" :)

I'm just glad somebody already figured out how to order Pizza online so I don't have that hanging over my head ;)

Cheers,


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/bin/bash

#
# ency.sh - More than you ever wanted to know about anything
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

if [ $# -lt 1 ]
then
echo "Usage: $0 Your Encyclopedia Terms"
echo "May be two or more words separated by spaces"
echo "but only one definition per execution."
echo "Ex: $0 money"
echo "Ex: $0 the beatles"
exit 1
fi

args="$@"
wget=/usr/bin/wget
pager=/usr/bin/more

if [ $# -gt 1 ]
then
args=`echo $args|sed 's/ /%20/g'`
fi

echo

$wget -nv -O - http://www.reference.com/search?q="$args" 2>&1|grep -i "No results found" >/dev/null 2>&1

anygood=$?

$wget -nv -O - http://www.reference.com/search?q="$args" 2>&1|grep -i "<cite>" >/dev/null 2>&1

toomuch=$?

if [ $anygood -eq 0 ]
then
args=`echo $args|sed 's/%20/ /g'`
echo "No results found for $args"
exit 2
fi

if [ $toomuch -ne 0 ]
then
args=`echo $args|sed 's/%20/ /g'`
echo "Too many results returned for $args"
echo "Try doing a broader query - For Ex:"
echo "$0 linux = Too many results"
echo "$0 linux os = Information!"
echo "Double check at www.reference.com"
echo "to see the difference"
exit 3
fi

$wget -nv -O - http://www.reference.com/search?q="$args" 2>&1|sed '1,/Cite This Source/d'|sed '/External links\|See also\|More from Wikipedia/,$d'|sed -e :a -e 's/<[^>]*>/ /g;/</N;//ba' -e 's/$/\n/'|$pager

exit 0


, Mike




Douglas Taylor submitted these enhancements to make the output look much nicer. Thanks, Douglas!


1) Run the output through fmt before outputting. It will wrap the paragraph text fairly nicely, although it kind of destroys tabular data, and the indenting can get weird, or

2) Use lynx with the -dump option instead of wget. I replaced the final wget command with

lynx -dump http://www.reference.com/search?q="$arg" |sed '1,/Cite This Source/d'|sed '/External links\|See also\|More from Wikipedia/,$d'|sed 's/\[[0-9]*\]//g'|$pager

and the result looks fairly nice.


Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Friday, June 27, 2008

SunCluster Quick Command Reference

Hey There,

Well, sitting back and reflecting today, I realized that we've done our fair share of posts on cheat-sheets and such (Our LVM command reference, for example). However, when it comes to clustering systems, we've probably been unfair in our bias toward Veritas Clustering as opposed to SunCluster, for which we've only put up, I believe, one post with our Simple SunCluster Monitoring Script (Thankfully linked back to from The SunCluster Wiki). What's a poor blog to do? ;)

With that in mind, today we're going to lay down a quick command reference for SunCluster. Hopefully you'll find it useful and enjoy it :) Of course, it assumes that you know, mostly, how to use SunCluster (and are familiar with basic clustering concepts), but it can be used as an attractive wallpaper, if nothing else ;)

All of this information, and much more, can be found at Sun's Online Documentation Center for SunCluster.

Enjoy,

Quorum Commands:

host # clquorum add device
- Add a SCSI Quorum Device
host # clquorum add -t netapp_nas -p filer =nasdevicename,lun_id =IDnumdevice Nasdevice - Add a NAS Quorum Device
host # clquorum add -t quorumserver -p qshost =IPaddress, port =portnumber quorumservername - Add a Quorum Server
host # clquorum remove device - Remove a Quorum Device

Resource Type Commands:

host # clresourcetype register type
- Register a Resource Type
host # clresourcetype unregister type - Remove a Resource Type

Resource Group Commands:

host # clresourcegroup create group
- Create a Failover Resource Group
host # clresourcegroup create -S group - Create a Scalable Resource Group
host # clresourcegroup online + - Bring Online All Resource Groups
host # clresourcegroup delete group - Delete a Resource Group
host # clresourcegroup delete -F group - Delete a Resource Group and All of Its Resources
host # clresourcegroup switch -n nodename group - Switch the Current Primary Node of a Resource Group
host # clresourcegroup unmanage group - Move a Resource Group Into the UNMANAGED State
host # clresourcegroup suspend group - Suspend Automatic Recovery of a Resource Group
host # clresourcegroup resume group - Resume Automatic Recovery of a Resource Group
host # clresourcegroup set -p Failback=true + name=value - Change a Resource Group Property
host # clresourcegroup add-node -n nodename group - Add a Node To a Resource Group
host # clresourcegroup remove-node -n nodename group - Remove a Node From a Resource Group

Resource Administration Commands:

host # clreslogicalhostname create -g group lh-resource
- Create a Logical Hostname Resource
host # clressharedaddress create -g group sa-resource - Create a Shared Address Resource
host # clresource create -g group -t type resource - Create a Resource
host # clresource delete resource - Remove a Resource
host # clresource disable resource - Disable a Resource
host # clresource set -t type -p name=value + - Change a Single-Value Resource Property
host # clresource set -p name+=value resource - Add a Value to a List of Property Values; Existing values in the list are unchanged.
host # clresource create -t HAStoragePlus -g group -p FileSystemMountPoints=mount-point-list -p Affinityon=true rs-hasp - Create an HAStorage Plus Resource
host # clresource clear -f STOP_FAILED resource - Clear the STOP_FAILED Error Flag on a Resource

Device Administration Commands:

host # cldevicegroup create -t vxvm -n node-list -p failback=true vxdevgrp
- Add a VxVM Device Group
host # cldevicegroup delete devgrp - Remove a Device Group
host # cldevicegroup switch -n nodename devgrp - Switch a Device Group to a New Node
host # cldevicegroup offline devgrp - Bring Offline a Device Group
host # cldevice refresh diskname - Update Device IDs for the Cluster

Additional Administration and Monitoring Commands:

To add a Node to Cluster:


From the node to be added, which has access:

host # clnode add -c clustername -n nodename -e endpoint1, endpoint2 - Use this only if the node has access to the cluster

To remove a Node From the Cluster:

From the node to be removed, which is in noncluster
mode and has access:

host # clnode remove - Use this only if the node has access to the cluster

host # clnode evacuate nodename - Switch All Resource Groups and Device Groups Off of a Node
host # clinterconnect disable nodename:endpoint - Manage the Interconnect Interfaces
host # clinterconnect enable nodename:endpoint - To disable a cable so that maintenance can be performed, then enable the same cable afterward.
host # cluster status - Display the Status of All Cluster Components
host # command status - Display the Status of One Type of Cluster Component
host # cluster show - Display the Complete Cluster Configuration
host # command show Component - Display the Configuration of One Type of Cluster
host # command list - List One Type of Cluster Component
host # clnode show-rev -v - Display Sun Cluster Release and Version Information

To list the software versionson the current node.

host # clnode show | grep nodename
- Map Node ID to Node Name
host # cltelemetryattribute enable -t disk rbyte.rate wbyte.rate read.rate write.rate - Enable Disk Attribute Monitoring on All Cluster Disks
host # cltelemetryattribute disable -t disk rbyte.rate wbyte.rate read.rate write.rate - Disable Disk Attribute Monitoring on All Cluster Disks

SHUTTING DOWN AND BOOTING A CLUSTER

To shut Down the Entire Cluster:

host # cluster shutdown

From one node:

host # clnode evacuate
host # shutdown - Shut Down a Single Node


To boot a Single Node from the OBP:

ok> boot

To reboot a Node Into Noncluster Mode from the OBP:

ok> boot -x

, Mike

Sunday, March 23, 2008

Apt and Yum Command Cross Reference

Hey there,

Today, we're following up on yesterday's post of our common PKG and RPM command cross reference. Hopefully, this will enhance our previous post by providing the equivalent apt and yum commands for the Solaris Unix pkg and RedHat Linux RPM commands (where they exist) that we went through yesterday..

The format for the list below, will be the same as our PKG and RPM reference and we'll present the actions in the exact same order, so you can put the posts side by side and translate between all four package manipulation methods at a glance. Again, the format is:

What We Want To Do: APT command - YUM command
<--- with PKG being the package name.

Enjoy your Sunday and hope this helps you out. If you know of any way to do a lot of these things with apt or yum that I don't, please feel free to email me and I'll be glad to update this page :)

Show package info: apt-cache show PKG - yum info PKG
Install package: apt-get install PKG - yum install PKG
Remove package: apt-get remove PKG - yum remove PKG
List the package that owns a particular FILE: Can't be done to my knowledge - yum provides PKG
List all files in an already installed package: Can't be done to my knowledge - Can't be done to my knowledge
List all files in an uninstalled package FILE: Can't be done to my knowledge - Can't be done to my knowledge
List all packages installed on your system: Can't be done to my knowledge - yum list installed
Check that all files from a package are installed correctly: Can't be done to my knowledge - Can't be done to my knowledge
Check that all files from all packages are installed correctly: Can't be done to my knowledge - Can't be done to my knowledge
Check that a package FILE is OK before installing: Can't be done to my knowledge - Can't be done to my knowledge
Fix an altered package installation: Can't be done to my knowledge - Can't be done to my knowledge


Cheers,

, Mike






, Mike




Saturday, March 22, 2008

Common Pkg And RPM Command Cross Reference

Hey there,

Today, I thought I'd put out a little summary, if you will, to wrap up all the pkg-to-rpm-to-pkg type articles we've been dealing with for the last few weeks and try to boil it down to a quick cross reference. This way you can have, at a glance, the basic information you need to manipulate both Solaris Unix pkg files and Linux RedHat RPM's.

You can find more detailed information, if you prefer, in our previous posts on working with Linux RPM's and building Solaris packages. I have yet to write a post on working specifically with pkg files (just lots of different aspects), but I suppose I ought to now, huh? ;)

This will be pretty straightforward, with a format of:

What We Want To Do: RPM command - PKG command
>--- With PKG and RPM being the actual pkg and RPM names

Enjoy, and I hope this helps save you some time digging around We will most likely look at the apt and yum equivalents of these commands very soon, as well :)

Show package info: rpm -qi RPM - pkginfo -l PKG
Install package: rpm -ivh RPM_FILE - pkgadd -d PKG_FILE
Remove package: rpm -e RPM - pkgrm PKG
List the package that owns a particular FILE: rpm -qf FILENAME - pkgchk -l -p FILENAME
List all files in an already installed package: rpm -ql RPM - pkgchk -l PKG
List all files in an uninstalled package FILE: rpm -qlp RPM_FILE - pkgchk -l -d PKG_FILENAME
List all packages installed on your system: rpm -qa - pkginfo
Check that all files from a package are installed correctly: rpm -V RPM - pkgchk PKG
Check that all files from all packages are installed correctly: rpm -Va - pkginfo|awk '{print $2}'|xargs pkgchk
Check that a package FILE is OK before installing: rpm -K RPM_FILE - pkgchk -d PKG
Fix an altered package installation: rpm --setperms/--setugids RPM - pkgchk -f PKG


Cheers,

, Mike