My own cool hacks?

Posted by on June 1, 2006

Inspired by a story on Slashdot about ?cool hacks?, I decided to sit down and write my own little tale of some of the more elaborate or interesting ?hacks? I have done. Now keep in mind, these are not all hacking as you might think. A cool hack sometimes is just a way you pieced software and hardware together, to get a job done. Here are some of my finer moments?


When I worked for Norampac, I wanted all of my servers to shut down gracefully in the event of a power failure but I was only able to detect the UPS battery from my main server and none of the others (a single UPS for all servers), and I also wanted to be notified on my cell phone when this all happened but unfortunately, I didn?t have access to a lot of gear that I could use, so I had to be creative in how I did this. This is perhaps the most convoluted hack I ever did, but none the less, it worked.

For starters, my main file server ran PowerChute as the power management software. It detected when the power went out and shut the box off before the battery would die. The fact that this ran on a Novell box complicated matters as I could not run any kind of batch file or any Windows app. So, the software did allow me to run an NCF file which is like a batch file but only runs on the Netware server. NCF files have almost no functionality, but they can copy files. So, I made an NCF file that would copy a file out of a directory and name the file DOWN.DAT and placed it into a specific directory. Because I had other servers that were connected to the Netware network, I wrote a little program in VB that ran on those machines that polled the directory for that file and when it found it, it shut the server down (via a VB API call). No problem.

However, this didn?t solve two problems. Problem number one was that I also had a Linux machine that needed to be powered down. Problem number two was that I still wasn?t being notified of the shutdowns. So, in Linux, I mounted that same directory from the Netware box as a directory in Linux, and wrote a small little bash script which ran every minute or so to check and see if the file was there (much like the VB app). If it was, the server performed a ?halt? which powered the machine down. Now, fortunately, I also had the ability for this Linux box to send email (via sendmail command line) which meant I could send email to my cell phone as an SMS message, and get the message that the servers were going down. I was all set.

I performed an in-house test and everything was working great. My servers started powering down one at a time and my Linux box sent off the email. Only one problem, I never got the message on my phone.

Turns out, the Linux box can?t send email outside of the internal network (no fault of the OS, just the internal network security). No internet email permitted. So how was I going to get the message to the outside world? Via Groupwise and rules.

I created a rule in my own Groupwise account (Groupwise is an email client like Outlook, used mainly in Netware environments) that said, ?If you get an email from this address, send this new email to this new email address?. The ?from? email was the Linux box and the ?new? email address was my cell phone. Since I could send email internally, I simply had the Linux box email my internal account a message, which then triggered a rule to send an email to my phone. Since the rules are processed by the Groupwise server and not the client, it would always run regardless of whether I had the application open on my workstation. It all worked beautifully when done.

So, to surmise, a program running on a Netware box triggered a Netware batch file to create a file which was picked up by a VB app on several Windows servers, and a script on a Linux box which then sent an email to an internal Groupwise account that triggered a rule to send a message to a cell phone. Seriously nasty, but it worked.

Another hack I did was also during my Norampac days and involved another combination of software and programming to achieve an end result. In this case, I had an employee who wanted to be able to email a quote to a customer.

The quotes on their system (at the time) were simply ASCII generated text from a Unix host that was sent directly a LPD printer which used pre-printed letterhead. The users had no access to the file system on the Unix box but did log in and use a custom menu driven application. What I learned was that when a user generated a quote, it created the flat text file in their home directory, and always used a certain file naming convention. I also learned that they could access their home directory via FTP. So this got me started.

First, I built a flat Microsoft Word file that matched the look of the pre-printed letterhead. I saved this as a document in a shared folder on the network. If I could get the flat text from the Unix box into that document, I?d have a working electronic copy of the quote.

Getting the flat text file would also prove to be an issue. I knew that if I could connect to the Unix box via FTP, retrieve a directory listing, I could use the date/timestamp on the files to know which one was the most recent (the one containing the most recent quote). So, I wrote a little batch file which used the user?s username and password to connect to their ftp account, did a directory listing, and piped all of the output to a text file. I then wrote a QB application that scanned that file and retrieved the name of the most recent quote file and generated a new batch file which the previous batch file would call. The new batch file would once again connect to the ftp server, download the quote data file, and then exit.

Once I merged the data file into Word, there were issues. Unix was generating these quotes with control codes that would throw off Word. I needed to filter these. So, I built that into another QB application (I eventually merged all apps into one, and separated the functionality by command line options).

The next part was getting the stripped raw data into Word, and reformatting it so that the fonts looked good, and page breaks were correct, and most importantly, it loaded the quote data file automatically. So, I did it with a macro. I created a macro which when run (and it ran automatically when the document opened) would import the data file, re-format it, and then prompt you if you wanted to save/print it.

When it was done, the process worked beautifully. My office folks had electronic versions of their quotes which they could now email or reprint at any time, and it saved us from having to use letterhead all the time.

So, to surmise, a batch file calls the FTP program with an answer file which connects to a Unix host to retrieve a list of files which itself is stored in a file which then gets scanned by a QB (QuickBasic) program to find the most recent file, and generates a new batch file which is then called that reconnects to the ftp site, downloads the new file, runs a filter application against the data file to remove control codes, and then launches an MS Word document which contains a macro which then loads the data file, reformats it, and prompts the user on how they want to distribute the document.

Man, do I love making weirdass hacks like those!

Leave a Reply