Tuesday, May 13, 2008

lftp

LFTP is sophisticated ftp/http client, file transfer program supporting a number of network protocols. Like BASH, it has job control and uses readline library for input. It has bookmarks, built-in mirror, can transfer several files in parallel. It was designed with reliability in mind. LFTP is free software, distributed under GNU GPL license.

So says the website. I do know it is all that and a bag of chips. A better FTP than whatever creaky FTP program is on your computer? Sign me up.

But there is more.

I own an application that - once in a great while - has bits of it just stop. It's not really obvious in it's log when this happens, but it's glaringly obvious in it's status web page when it does. Words like FAILURE pop up and replace 'Success'.

Whop-te-do! I don't look at a web page every five minutes. This is the 21st century. Computers exist to do this kind of thing for us.

curl could do it - curl the page, grep the contents for the word 'FAILURE' but ... dragging the entire page down to look for a word? That's so .. 1990s. Plus it takes about 10 seconds.[1]

Enter LFTP. Now what I'm doing is this this; there are seven services listed on this page. If there aren't at least seven instances of the word Success on that page, something is wrong.

Knowing this is enough. And it takes less than a second [1] for lftp to return the number from the page.


$ basic_alert_script.sh
#!/bin/bash
lftp -f control_file > value
num=`cat value`
if [ $num != "7" ]; then mailx -s Your_lame_application_is_broken helpme@company.com < /dev/null ; fi

$ control_file
open http://application.company.com:8080/myweb/page
cat page | grep Success | wc -l
exit


FTP centric lftp tutorial, here.

[1] YMMV.
blog comments powered by Disqus