Hope this helps, Don
Let me know what else I can provide, such as more of what these called programs contain. Essentially, the "my_job" runs for up to 90 seconds maximum and then deposits whatever results in its own file for retrieval by the "unloader".
The Garbage Collection routine periodically checks for "heartbeat" files that haven't been updated in several minutes, tries to kill the number of the process inside it, if its still alive, and then discards the file.
#!/bin/bash
_last_update="Tue Jan 14 12:39:23 CST 2015"
# Linux 2.6.32-431.29.2.el6.x86_64 #1 SMP Sun Jul 27 15:55:46 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
#
COL_C_TIMESTAMP=1
COL_C_COMMAND=2
###############################################################
# 3. INSTALLATION-DEPENDENT VARIABLES
###############################################################
### Place on WFE where all this cool stuff happens
# WFE_HOME=`pwd`
WFE_HOME=/home/gmark/rje
### Place on Splunk server where other cool stuff happens
# Server where WFE is running
WFE_SERVER=wfe.ready.com
WFE_CONTROL=${WFE_HOME}/op-control
### Message Buffer directory
WFE_MSGS=${WFE_HOME}/MSGS
# Scheduled Global Abate done today already?
SGA_STAT_FILE=${WFE_HOME}/wfe-sga-donetoday
echo NOT_DONE > ${SGA_STAT_FILE}
### Archive file of CSV commands for SIMULATOR
CSV_INPUT_ARCHIVE_FILE=${WFE_HOME}/csv-command-archive-file
# Common name of CSV file on both systems
CSV_NAME=work.csv
# Type of command used to transfer files
XCOMMAND=sftp
# Path to Heartbeat Timestamp file
HEARTBEAT_FILE=${WFE_HOME}/wfe-heartbeat
touch ${HEARTBEAT_FILE}
###############################################################
# 4. MASTER PROCESS CONTROL FILE READ
###############################################################
#
### WFE ROP used to log debug and for status information
WFE_2_ROP=${WFE_HOME}/wfe-ropfile
### WFE Logfile used for communication to Splunk
WFE_2_SPLUNK=${WFE_HOME}/wfe-logfile
# WFE Process ID used to enforce single System Process
WFE_PID_FILE=${WFE_HOME}/wfe-process-id
# Initialize Process ID to Enforce threading requirements
THIS_WFE_PID=$$
echo ${THIS_WFE_PID} > ${WFE_PID_FILE}
# Initial index of records in local CSV input file
CMD_INPUT_POINTER=9999999
# Initial size of Local CSV Command Buffer
LOCAL_CSV_SIZE=0
# Initial Assumed Oldest ALERT Timetstamp
LOCAL_CSV_BIRTHDAY=0
CALC_TIMESTAMP=`date "+%s"`;
###############################################################
# 5.
CHECK CLONE STATUS
###############################################################
#
while [ true ]
do
MASTER_WFE_PID=`cat ${WFE_PID_FILE}`
if [ ${THIS_WFE_PID} != ${MASTER_WFE_PID} ]
then
echo "...`date "+%Y-%m-%d %H:%M:%S"`: Execution Stopped ..." >> ${WFE_2_ROP};
exit 0
fi
###############################################################
# 6. WORK TO DO? IF NOT, GET SOME.
###############################################################
wfe\_msg_unloader &
wfe\_garbage_collection &
NOW_TIME=\`date "\+%s"\`;
CSV_AGE=$\(\( $\{NOW_TIME\} - $\{LOCAL\_CSV_BIRTHDAY\} \)\)
\# Out of ALERTS? MOVE CSV from Splunk to WFE - purge any aging ALERTS
if [ $\{CMD\_INPUT_POINTER\} -ge $\{LOCAL\_CSV_SIZE\} -o \\
$\{CSV_AGE:=0\} -gt $\{MAX\_ALERT\_REQ_AGE\} ]
then
touch $\{HEARTBEAT_FILE\}
cat /home/gmark/rje/COMMANDS.csv | grep "A[BL][AE]" > $\{LOCAL_CSV\}
> $\{REMOTE_CSV\}
LOCAL\_CSV_SIZE=\`wc -l $\{LOCAL_CSV\} | sed "s;^ *;;" | sed "s; .*;;"\`
LOCAL\_CSV\_BIRTHDAY=$\{NOW_TIME\}
CMD\_INPUT_POINTER=0
fi
while read CMD_INPUT
while [ true ]
do
###############################################################
# 8. VERIFY RUN STATUS, ELSE RESET NOW TIMER
###############################################################
touch $\{HEARTBEAT_FILE\}
# An external "control" file with RUN=YES or RUN=NO to turn this off
RUN=`wfe_set_control RUN YES`
if [ ${RUN} != YES ]
then
echo "... ${NOW_TIME}: RUN=${RUN}: Execution Stopped by Request ..." >> ${WFE_2_ROP}
exit 0
fi
CMD\_INPUT_POINTER=$\(\( $\{CMD\_INPUT_POINTER\} \+ 1 \)\)
NOW_TIME=\`date "\+%s"\`;
CSV_AGE=$\(\( $\{NOW_TIME\} - $\{LOCAL\_CSV_BIRTHDAY\} \)\)
if [ $\{CSV_AGE:=0\} -gt $\{MAX\_ALERT\_REQ_AGE\} ]
then
> $\{LOCAL_CSV\}
fi
# This allows "read" statements to be placed in the loop for debugging
CMD_INPUT=`cat ${LOCAL_CSV} | head -${CMD_INPUT_POINTER} | tail -1`
touch $\{HEARTBEAT_FILE\}
\# Better ways to do this, but none as dependable
C_COMMAND="\`echo $\{CMD_INPUT\} | cut -d, -f$\{COL\_C_COMMAND\}\`"
if [ $\{C_COMMAND\}x == ALERTx -o $\{C_COMMAND\}x == ABATEx ]
then
echo $\{CMD_INPUT\} >> $\{CSV\_INPUT\_ARCHIVE_FILE\}
C_TIMESTAMP="\`echo $\{CMD_INPUT\} | cut -d, -f$\{COL\_C_TIMESTAMP\}\`"
# Heartbeat file checked by another process to make sure this is still running
touch ${HEARTBEAT_FILE}
# Uses Modulus function to do only periodic calls to the Unloader
# The Unloader checks for completed output files to forward to user
if [ $(( ${CMD_INPUT_POINTER} % ${MAX_UNLOADER_DELAY})) == 0 ]
then
wfe_msg_unloader &
fi
NUM_PROCS=\`ps -u root | grep wfe\_voice_ | wc -l\`
if [ $\{NUM_PROCS\} -lt $\{MAX\_NUM_PROCS\} ]
then
my_job "$\{CMD_INPUT\}" &
else
sleep 1
fi
else
echo at $\{LINENO\} BOGUS COMMAND - SKIPPED >> $\{WFE\_2_ROP\};
fi
# done < ${LOCAL_CSV}
done # Test Version for setting breakpoints
done # while TRUE[/CODE]