I'm William L. Dye ("willdye"), a programmer from Lincoln, Nebraska, USA. I'm not a Bash expert, but I've contributed to this wiki in the past, and might contribute again sometime, so I might as well create an account here.

I typically program in C/C++, Tcl/Tk, and Bash; and occasionally program in Python, Awk, and Lisp. I can't even remember all the languages I've used over the years, but it's a long list (Fortran, APL, various assembers, et alibi). I can also use Java. If I have to. I guess.

I currently program on the Windows and Linux platforms, mostly in the XP and Red Hat varieties. In the past, I've used IBM mainframes (mostly 370 MVS), BSD, HP/UX, and Macintosh. In acient days of long ago, I've used CP/M, DOS, Amiga, CDC mainframes, TRS-80, Commodore 64, Altair 8800, custom machine controllers (8080 and Z-80), and a bunch of other crufty old things that I can barely even remember now.

Yeah, I'm that old. And just so you know, we really did walk 20 miles to school and back, and it was uphill both ways! And we didn't have your fancy ones and zeros back then. Why, I had to write an entire database with just zeros! Wimps! Learn to program using a soldering iron, ya slackers! Mutter, mutter, mumble...


Personal sandbox area

This is some code that I might post in the Bash FAQ or open questions pages, if I can determine that it's a good solution (or fix the problems, if I can find any). Do NOT trust this code -- it's just a draft.

Suppose you have multiple computers, only one of which operates your desktop environment, and you want the other machines to notify the desktop machine if something noteworthy happens. The definition of "noteworthy" doesn't matter to this example code, but it could be a disk which is getting dangerously full, or incoming mail that matches a certain pattern.

Here's some very simple Bash and Tcl code which demonstrates a basic framework that you could use to create such a system. It's based on the ability of Bash to use "/dev/tcp" as a way to easily send messages to TCP ports.

On the desktop machine, run this at a Bash prompt, or put the equivalent into a Tcl program:

tclsh<<<'
proc respond {channel address port} {
  puts "$channel $address $port [gets $c]";
  close $c};
socket -server respond 8765;
vwait forever'

On the other machine(s), run this Bash program:

while sleep 3;
  do date > /dev/tcp/desktop.yourdomain.com/8765;
done

...where "desktop.yourdomain.com" is the name or I.P. address of your desktop machine.

If that fails, then don't bother making the programs any fancier until you figure out what's wrong. If your firewall is blocking the port, or the port is in use by another program, try some other port.

If it works, then every three seconds or so, you should see the current date appear on the server side. Now you can extend the programs to start some function whenever a particular condition is satisfied.


CategoryHomepage