I hate 'clever' programmers (Revenge of the Mover)



  • Found in another mover script. This one processes the secondary data feed (the other one I showed the other day is for the primary.) This one is doing something wonderful, somehow checking to see if the primary data feed has had files in the past N minutes, and if it hasn't seen data in that amount of time, use the secondary data feed's input and dump it into the application's input queue(s). I'm still trying to figure out how it works. At the top, I found this which, while I understand what it is doing, I don't yet understand why:

     

    #!/bin/csh -f
    

    .
    .
    .
    set LOGFILE = /app/logs/redundancy_mover.log
    set APP_REDUNDANCY_FILE = /tmp/APP_REDUNDANCY_FILE
    set TIMESTAMP = date +'%m-%d-%Y %H:%M: '
    if ( -e ${APP_REDUNDANCY_FILE} ) THEN
    touch -t perl -e '$d = time(); $d -= 1800; @f = localtime($d); printf "%02d%02d%02d%02d%02d", $f[5]+1900, $f[4], $f[3], $f[2], $f[1];' ${APP_REDUNDANCY_FILE}_tmp
    set lastfiles=`find ${APP_REDUNDANCY_FILE} -newer ${APP_REDUNDANCY_FILE}_tmp
    rm ${APP_REDUNDANCY_FILE}_tmp
    if ($#lastfiles > 0) then
    echo "$TIMESTAMP already running, stopping..." >>! ${LOGFILE}
    exit
    else
    echo "$TIMESTAMP Last run errored out, continuing..." >>! ${LOGFILE}
    endif
    else
    touch ${APP_REDUNDANCY_FILE}
    endif

    .
    .
    .

    So, if the redundancy file exists, create a file with the date 1800 seconds (minutes?) ago and grab a list the files in the directory which are newer than that. If that list has values, then oops! We're already running. Quit now. If the list of files is empty, then the script was aborted part way through last time, so continue and give it another go.

    If the redundancy file doesn't exist, create it for the next time through.

    Is the redundancy file acting as a lock file to keep the program from running again? If so, why the hell name it APP_REDUNDANCY_FILE instead of, oh, I dunno, APP_LOCK_FILE?

    TRWTF is Solaris for not having a find command with a minute-granular -mtime parameter.



  • Apart from the variable name and the data race, I really like that and the original writer was absolutely certain that the script will never ever run longer then 1800 seconds.



  •  @m said:

    Apart from the variable name and the data race, I really like that and the original writer was absolutely certain that the script will never ever run longer then 1800 seconds.

    $10 says that a previous version of the script had "$d -= 300;" because the script will never ever run longer than 5 minutes :-).

     

     



  • According to both you the runtime of the script differ



  • Joke's on all of us!

    There's a "sleep 120" command later in the script ...



  • TRWTF is invoking a Perl one-liner from a CSH script, instead of writing the whole thing in Perl.

    Seriously, even Perl is better than CSH.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.