Cooking with Linux—The French Connection
Allo, and welcome to Chez Marcel, home of fine French Linux cooking.
Please take a seat. If you have not already done so, I would like you to read this article with a somewhat exaggerated French accent since that is the way I wrote it. Even the README files are heavily accented. For those of you who, like myself, are French, you may translate as you read, thus adding another level of authenticity to the excellent menu that awaits you.
It is an honour and a privilege to welcome you to my kitchen. Tonight, I have a special treat for you. The recipes I have prepared are made from common Linux distribution ingredients so that you can recreate these delicacies when you return to your own kitchen CPU. Tonight's menu:
Mail notification for Windows clients
What's my IP?
diald Control
Waiter! More disk.
Waiter! There's a fly in my system.
Is it That Time Already?
I must tell you right now that I am thrilled you have decided to join me in my kitchen. Much of what I have in store for you is designed to make Windows 9x more productive with a little help from Linux. If you have already cast away your Windows PC but you miss some forgotten piece of software (provided that software is not too demanding), you could check out http://www.winehq.com/ for the latest version of the Windows non-emulator for Linux.
For many users out there, the Windows workstation is still on the desktop, while the Linux machine performs such noble tasks for the Windows user as connecting to the Internet, providing firewall services, delivering mail, sharing disk space and printers, among other services.
What we have in store for you here today are Linux scripts that can make your Windows experience more enjoyable.
In the next few examples, we will have our Linux system talk back to Windows. While that is a good idea, we must first set up Windows to listen; otherwise, all our talk will disappear into the proverbial ether. When our Linux system needs to contact a Windows user, it will do so using Samba's smbclient messaging functionality. Obviously, that requires a system running Samba. On the Windows side, it requires Winpopup.
To set up Winpopup to start each time you boot Windows, create a shortcut in the Windows Startup folder. Click on the Start button, then Settings, then Taskbar. Choose the tab that says “Start Menu Programs”, then click the Advanced button. This will open a Windows Explorer window. Open the Startup folder under Programs and add a shortcut to winpopup.exe. Accept the default name, and you will wind up with a cute little Jack-in-the-box icon. Right-click on it to access the properties tab. Now, set the Run: option to Minimized. Winpopup starts up out of the way, and pops up only when it gets a message. Double-click the icon to start it right away.
One more thing: you should now see Winpopup sitting minimized on your taskbar. Click on it to bring it up. Now click on Messages, and choose Options from the drop-down menu. Click the box for “Pop up dialog on message receipt”. Click OK and re-minimize Winpopup. Windows is now ready to receive messages from your Linux system, which brings us to the next item on the menu.
This is a frequent question we get from users. You are the administrator of a small- to medium-size office; you've set up an Internet gateway that picks up the mail on a regular basis using fetchmail, which then stores it on your Linux server. The problem is that your users are still running Windows with some sort of stand-alone POP3 e-mail package like David Harris' Pegasus Mail. While many packages can be set up to retrieve mail automatically, keeping them open and running taxes their already taxed Windows system. This means users tend to point out how slowly their systems are running. You suggest they close a few applications. “How about e-mail?” you suggest. To which they reply, “What if I miss an important message?” The solution is the checkusermail script shown in Listing 1.
In /usr/local/etc, create a small text file called mail_notify with the names of users who receive mail on your system. If the Windows clients are named differently (in the network configurator of the Windows control panel) than the user ID for mail, create an /etc/lmhosts file with IP addresses matching your mail user IDs, and the results should be the same. The script can be run from cron at whatever time interval suits your environment. Since it runs as root, it can spy into everyone's mailbox with the frm command. It will tell each user they have mail and how many messages. If there is no mail, there is no message and no need to waste time and energy checking every few minutes.
Another happy soul you'll discover after you deploy this script is the boss who had been complaining about either the amount of time users spent checking mail, or the user who did not check it often enough and missed an important message.
In the last example, I talked about the beleaguered administrator (is there any other kind?) and suggested this might be a useful tool for them as well. What if you are administering that system from far away? Worse yet, this Internet gateway runs on a budget—it's a simple dial-up connection to an ISP running diald and IP masquerading. When trouble strikes, they call you. Trouble means you use TELNET to log in, check things out and fix the problems remotely. Trouble is, the IP is dynamic and changes with each connection to the ISP. The solution this time is the showppp.pl script shown in Listing 2. The script is simple and lives in cgi-bin. Depending on your web server setup, you might want to rename this one showppp.pl.
Setting up a simple Intranet for your users is a breeze. A nice corporate home page with some popular links to the Internet makes it easier on your resources than having each user start up their browser with http://www.cnn.com/ or http://www.excite.com/ as their start page. If your dial-up connection gives you only a fixed number of hours per month, that time can get chewed up very quickly.
Why not use that same page and give your users a link to a script that will display the IP address of your dial-up IP connection without requiring them to log in to your Linux server? Figure 1 shows just such a page.
Every once in a while, the diald process may get hung up. Sometimes the modem has gotten hung up and diald can't seem to drop it. In either case, the easiest way to get life back to normal is to stop diald and restart the process. Since you are operating remotely and want to make this as painless as possible, you can either do the work yourself or talk one of your remote users through the process. It would be so much easier if they could just type one command, rather than doing a ps ax | grep diald while hoping they kill the right PID and not bring your system down. Listing 3 is a little script to do just that. The user simply types:
diald.control restart
to get things moving again. You can also use the script to stop diald, start it, or shut it down and start a single instance of mgetty in order to pick up a fax (but that's for another time).
You can use this example as a template to create any number of start, stop or restart scripts. When necessary, you can have trusted users log in to your server and run simple administration scripts like this one without risking damage to your system or the equally ominous possibility of killing an important process like init. After all, kill --1 looks very similar to kill 1, doesn't it?
Remember those great little messages for letting your users know they have mail? How about using that same technique to let you, the administrator, know that some important system event needs your attention? For example, suppose you are constantly battling disk space. Wouldn't it be nice if the system let you know that resources are low? With the next little Perl script (see Listing 4), you can have your Linux system send a pop-up message to your Windows workstation alerting you that system resources are low. This script scans disk partitions and reports to client speedy that disk space usage is over 90%. (See Figure 2.)
Figure 2. Disk Space Usage Screen
The Windows winpopup utility is a great tool for the user who still runs a Windows client but needs to get information sent to him from their Linux servers. This script and the earlier mail notification script highlight this flexibility.
By the way, the next item on the menu, the fly—that's just to get you thinking about other possibilities.
In my business, I've set up a number of Linux internet gateways. To make these installations as inexpensive as possible, we set the machines to dial every half hour or so to pick up mail. That half-hour mark is also our cue to log in using TELNET if we need to do some administration work on the machines. Unfortunately, the time on each machine can vary. How about a way to check the time against some reliable source and adjust the Linux server?
The script in Listing 5 is a bit of Perl magic. It opens a socket on a secondary time server, picks up the time, and closes the socket. This is a nice alternative to NTP in that it does not tax the NTP time server's resources. For that very reason, the NTP rules ask that you do not use primary servers if you don't need to. A link to the “Public NTP Time Servers” page is provided in Resources.
Notice the line in Listing 5 that says remote_host="chime.utoronto.ca";. The host specified here is chime.utoronto.ca, but it could be one of any number of machines which offer primary or secondary time services. Consider the rules, though, and visit the NTP time server page for a system in your area and time zone.
Well, that last script on time was my way of getting all of you out of the restaurant. I hope you'll pay another visit to Chez Marcel. We hope we've succeeded in whetting your appetite for some of the wonderful and fun things you can do with a Linux system. Bon Appétit!
Marcel Gagné (mggagne@salmar.com) lives in the mythical city of Mississauga, Ontario. Besides being a space alien, adventurer, pilot, magician and international man of mystery, he is president of Salmar Consulting Inc., a systems integration and network consulting firm. He also writes science fiction and fantasy, and edits TransVersions, a science fiction, fantasy and horror magazine.