Originally posted by Jennifer Hardesty
####################################################################### Name: tps_ftp_dft# Purpose: select the files on the host system to processes# UPoC type: tps# Args: tps keyedlist containing the following keys:# MODE run mode ("start", "run" or "test")# MSGID message handle# ARGS user-supplied arguments:# FTP parameters are passed via the keyword FTPARGS as# a list in the following order separated by a , (comma):## FPTRN = The REGEX Pattern the script will use to recognize# the file to be picked up## Returns: tps disposition list:# Returns a list of messages for the fileset# driver to process.#proc tps_ftp_dft { args } { global HciConnName HciRoot HciSite HciSiteDir FTPIBDIR keylget args MODE mode ;# Fetch mode keylget args CONTEXT ctx global dft_startup set Process "[lindex [split [pwd] /] end]" set proc_name "tps_ftp_dft" set module "$proc_name" switch -exact -- $mode { start { # Perform special init functions # N.B.: there may or may not be a MSGID key in args # set flag to indicate process/thread startup. set dft_startup "1" echo "[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]" echo " PROC: $proc_name CONTEXT: $ctx MODE: $mode " return "" } run { # 'run' mode always has a MSGID; fetch and process it keylget args MSGID mh # If we have arguments, fetch them keylget args ARGS.FTPRN pattern echo "[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]" echo " PROC: $proc_name CONTEXT: $ctx MODE: $mode " # Check for correct context if {![cequal $ctx "fileset_ibdirparse"]} { echo "INFO: $module - ERROR $proc_name used in wrong context - $ctx" echo "Context should be fileset_ibdirparse" return "{CONTINUE $mh}" } # check for startup flag and set off if this is the first run after start. if {[cequal $dft_startup "1"]} { set dft_startup "0" msgset $mh {} } else { # all other actions in run mode occur only during a scheduled run, not startup run. set ibSaveDir [file join $HciSiteDir exec processes] set ibSaveDir [file join $ibSaveDir $Process InboundSave] # We want to archive the ftp'd files, so... # make sure "ibSaveDir exists, if not create it if {![file exists $ibSaveDir]} { echo " INFO: $module - creating InboundSave directory...." if {[catch {file mkdir $ibSaveDir} result]} { puts "INFO: $module - ERROR: $ctx - Unable to create "$ibSaveDir"" puts " result was: $result" } ;#end if } ;#end if # In the context the message handed to this proc # by the driver is not a data message. Rather # it is a space seperated string of file names # from the directory the fileset driver is # configured to read. # # The list of files to process is accessed # in the same way data messages in other contexts # are accessed. The string is split into a list # so that a TCL list sort operation may be # performed. The original message is updated # with the contents of the new list, and returned. # # The fileset driver then processes the files in the # order they appear in the returned message list. set msg_list [msgget $mh] set msg_list [split $msg_list] set msg_list [lsort -increasing $msg_list] set msg_list [lregexp $msg_list $pattern] echo "***n*** [clock format [clock seconds] -format "%m/%d/%y @ %H:%M:%S"] ***n" if {[llength $msg_list] != 0} { echo "***n*** INFO: $module - Remote files found to process: $msg_list n***" } else { echo "****************************************************" echo "***n*** INFO: $module - NO FILE FOUND TO PROCESS n***" echo "****************************************************" } msgset $mh $msg_list } return "{CONTINUE $mh}" } time { # Timer-based processing # N.B.: there may or may not be a MSGID key in args } shutdown { echo "*** $proc_name shutting down." } default { error "Unknown mode '$mode' in $proc_name" } }}