Microsoft and Linux Managed, Dedicated Servers

WebProWorld Dev Forum

Web Position Gold
Have for a while now owned a copy of Web Position Gold but never got round to testing it out. Would be interested in hearing comments on its usefulnes. It seemed a litle complicated on both times I took time to look at it.
Click to read more...

Thunderbird 1.0
Mozilla released Thunderbird 1.0. I was using 0.8 and upgraded today. So far I haven't found any of the new features to be anything I'll likely be using, but I think some people will find them handy.
Click to read more...

Blocking websites witout a server
I've been working at a high school and we're dealing with a problem. Our students are spending important time playing online games and using AIM through the web. We'd like to block certain sites, but we do not have a server. Does anyone have any suggestions on blocking certain websites? Any and all help would be appreciated.
Click to read more...



Recent Articles

Sun offering free, open source Solaris 10 - not quite yet
I'm reading everywhere that Sun is making Solaris 10 free and open source ( http://www.rednova.com/ news/ display/?id=106224). However, that's not quite true yet: if you go to their download pages, you;ll have to accept a license that says (among other things):

Sun and Open Source
We don't even yet know what Sun means by "open source", but already the pundits are arguing about whether making Solaris "open source" (whatever that turns out to mean) will help them or hurt them.

The Top 10 Essential Ingredients of Every LINUX HOSTING Plan (Package)
Any website comprises the following - Domain name, Webspace, Webpages. Lets say, You have got your Domain Name (www.yourdomain.com). Its time to check for a good hosting service provider to have your files uploaded in the domain.

Microsoft Scares Asia With Linux Lawsuit Warnings
Microsoft Chief Executive Steve Ballmer warned Asian governments that they could face patent lawsuits for using the open source Linux operating system.

Linux Networkx and Novell Create HPC Certification Center
Linux Networx has partnered with Novell to create a High Performance Computing (HPC) Certification Center located at Linux Networx to help Independent Software Vendors (ISV) certify their applications on Novell's SUSE LINUX Enterprise Server for use in clustered environments.

Rebuilding failed Linux software RAID
Recently I had a hard drive fail. It was part of a Linux software RAID 1 (mirrored drives), so we lost no data, and just needed to replace hardware. However, the raid does requires rebuilding. A hardware array would usually automatically rebuild upon drive replacement, but this needed some help.

Quality Assurance for Linux Training
The President of the Linux Professional Institute attended Linux World Expo in London to announce the launch of a quality assurance program for Linux training in the UK.

Configure-to-order Linux Cluster Solutions
Voltaire InfiniBand interconnect solutions for igh-speed, low-latency networking capabilities will be integrated into HP high-performance configure-to-order Linux cluster configurations.

Exchange Data Between Linux and Windows in Real Time
Linux programs can now exchange data in real time with a wide range of Windows programs, across a network or the Internet.


InSiteTM AdBuyer, Effective Search Marketing.
12.15.04


Custom Tab Completion

By A.P. Lawrence

I'm sure you already know about tab completion: type part of a command name and hit TAB and you get its matches. Leave a space and then hit TAB, and you get filenames. Wonderful stuff. But what if YOUR command wants user names instead of file names?

The newer versions of Bash (above 2.04) have Custom Tab Completion, which means that you can control what happens when TAB is typed after a command. You'll find the applicable sections in man or info for "bash" under the the descriptions of "compgen" and "complete".

Compgen

The "compgen" command is the magic behind all this stuff. Its usage is simple: compgen options word. For example, try this:

compgen -A user -- r

The "--" separates options from the word we are trying to match ("r"). I chose "r" because you probably have at least a "root" user. Try it with other letters or words that will match your user list:

compgen -A user -- to
tony


Or leave it blank:

compgen -A user
root bin daemon adm lp sync shutdown halt mail news uucp operator
games gopher ftp nobody rpm vcsa nscd sshd rpc rpcuser nfsnobody
mailnull smmsp pcap xfs ntp gdm desktop apache webalizer squid named
tony


Compgen can use the results of other commands or variables:

compgen -W '$( mount | cut -d" " -f 3)'
/
/proc
/dev/pts
/proc/bus/usb
/boot
/dev/shm


Complete

The options compgen recognizes come from the "complete" built-in. There are quite a few - see the bash man pages for all of them because I'll only discuss a few here. Let's try some of them:

$ compgen -W 'appl arctic bob sam' -- a
appl
arctic
$ compgen -A signal -- SIGA
SIGABRT
SIGALRM
$ compgen -A service -- power
powerburst
powerburst
powerguardian
powerguardian
powerclientcsf
powerclientcsf
powergemplus
powergemplus
poweroncontact
poweroncontact
poweronnud
poweronnud
powerschool
powerschool


Get Hundreds of Incoming Links - Instantly ->> more info

Fun, right? Obviously "compgen" could be very useful inside scripts to offer dynamic choices with little effort on your part. But it's even more fun when you use it with tab completion.

Custom Tab Completion

The first thing you have to do is enable custom tab completion. That's simply

shopt -s progcomp

The best place to do that is .bashrc and that's also where you'll want to put the rest of what we do. You CAN do it elsewhere, of course - there's nothing magic about having it in .bashrc, that's just a convenient place.

OK, now we have a script we've written. Let's called that "myprog":

#!/bin/bash
# myprog
# doesn't do much
echo Hi!


Be sure to put "myprog" somewhere in your PATH - shell tab completion will not work otherwise.

Next, we define a function that we will use for tab completion with "myprog":

_myprog()
{
local curw
COMPREPLY=()
curw=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -A user -- $curw))
return 0
}


In this function, "$curw" will be what you typed before hitting TAB:

myprog to

will end up (once we've activated this) with $curw being "to". We get that from the built-in $COMP_WORDS array. We then set COMPREPLY to be the output of compgen. Finally, we need to activate this and associate it with our command (add this to .bashrc also):

complete -F _myprog -o dirnames myprog

That's it. Check your work, and type "bash" to start up a new shell (so your .bashrc gets read) and type "myprog" followed by a space and a TAB. You should see user names listed instead of file names. If you did something wrong, you'll either see a complaint from compgen or a list of dirnames (because our "complete" included -o dirnames). Debug by running your compgen on the command line as shown in the first part of this article.

Other commands

Nothing prevents you from adding custom tab completion to normal system commands. Because the choices it offers can be generated by scripts you write, the possibilities are endless. How about a custom tab function for ssh that lists the places you normally ssh to? Or the same idea for ftp?

http://www.caliban.org/bash/#completion has some pre-made custom tab completion scripts that you can download to use or get ideas from.

* Originally published at APLawrence.com

About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

About LinuxProNews
LinuxProNews is a collection of news and commentary designed to keep you in step with the ever evolving landscape of Linux environments. Opensource News and Advice for Linux Professionals

LinuxProNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com DevWebPro.com


-- LinuxProNews is an iEntry, Inc. publication --
iEntry, Inc. 880 Corporate Drive, Lexington, KY 40503
2004 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article

Opensource News and Advice for Linux Professionals LinuxProNews News Archives About Us Feedback LinuxProNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact