UPS Tracker

by Gerald Oskoboiny


UPS has an online package tracking system that I used to watch my stuff in transit when I moved from Edmonton, Canada to Boston, USA.

This is cool and useful, but as of Nov 1997 they don't provide a way to get notified when the status of a package changed (i.e., when it moved from one point to another, or when it arrived at its destination.)

Who wants to visit a Web page 10 times a day to see if the status of your shipment has changed? Computers were invented to spare us this type of drudgery, not to create it.

Fortunately, with about 15 minutes of work I was able to write some stuff to make it send me e-mail whenever the status of my shipment changed, thanks to the awesome mail filtering software called procmail and the general ease of automating stuff in a Unix environment.

Here's how I did it:

  1. Added something to my crontab to send e-mail every hour inquiring about the status of my package:
        15 * * * * echo 36191550391 | mail totaltrack@ups.com
  2. Created a procmail recipe to intercept the incoming replies and send them to a shell script that checks if anything has changed:
        :0hb:/tmp/ups_track
        * ^From: .*totaltrack@ups\.com
        * ^Subject: UPS Tracking Information for
        | ups-track
  3. Wrote a shell script to check if anything has changed in the body of these incoming messages; if not, it just ignores the message; if so, it changes the Subject and forwards it on to me.
        #!/bin/sh
        #
        # ups-track: check if UPS messages have been seen already or not
    
        temp=/tmp/ups_track.$$
        upsdir=/home/gerald/ups-tracking-status
    
        # message comes in as stdin
        cat > $temp
    
        # compute checksum of message body
        checksum=`sed -e '/^$/,$!d' $temp | md5sum`
    
        if [ -f "$upsdir/$checksum" ]; then
    	exit        # seen this already
        fi
    
        touch $upsdir/$checksum
    
        formail -IApparently-To -I'Subject: UPS Shipment Status has changed!' < $temp \
    	| sendmail gerald@w3.org
    
        rm -f $temp
    
        exit 0

Whenever the status changed, I would get a message like this:

    Date: Thu, 13 Nov 1997 14:15:38 -0500
    From: TotalTrack <totaltrack@ups.com>
    Subject: UPS Shipment Status has changed!

    Tracking Result         
    Current Status:           Delivered                    
    Delivered on:             11-13-1997 at 1:24 PM        
    Received by:              OSKOBOINY                    
			    
    UPS Service:              WORLDWIDE SERVICE            
    Tracking Number:          36191550391                  

    Notice      
    UPS authorizes you to use UPS tracking systems solely 
    to track shipments tendered by or for you to UPS for 
    delivery and for no other purpose. Any other use of UPS 
    tracking systems and information is strictly prohibited. 

    Scanning Information    
    11-13-1997    1:24 PM     WATERTOWN-BOSTON WST, MA US  
			      DELIVERED                    

    11-12-1997    4:46 PM     CHELMSFORD, MA US            
			      LOCATION SCAN                

		  4:54 AM     CHELMSFORD, MA US            
			      ARRIVAL                      

    11-7-1997     1:50 AM     SALT LAKE CITY, UT US        
			      DEPARTURE SCAN               

    11-6-1997     6:37 PM     SALT LAKE CITY, UT US        
			      LOCATION SCAN                

    11-5-1997     12:57 AM    CALGARY, AB CA               
			      LOCATION SCAN                

		  12:13 AM    CALGARY, AB CA               
			      LOCATION SCAN                

		  12:12 AM    CALGARY, AB CA               
			      ARRIVAL                      

    11-4-1997     8:45 PM     EDMONTON HUB, AB CA          
			      DEPARTURE SCAN               

		  8:04 PM     EDMONTON HUB, AB CA          
			      LOCATION SCAN                
			      
			    


    Your message follows:
    >> 36191550391

Pretty cool for 15 minutes of work!


Valid HTML 4.0! Last modified: $Date: 1999-10-24 03:05:36 $
Gerald Oskoboiny, <gerald@impressive.net>