#!/bin/bash #from http://cvs.sourceforge.net/viewcvs.py/emc/emc_HAL/farm_scripts/run_farm?rev=1.3&view=auto TRY_CVS # This script reads the file "trees" in the current directory. It # cd's into each subdirectory listed there, does a cvs up, and if # any files have changed, it calls "build" in that directory, logging # its output to "build_log" # This function attempts to do a "cvs up", saving the results in # cvs_log. It does not interpret the results. It returns 0 if # the cvs command completes successfully, and 1 if it fails or # times out. # function TRY_CVS { # invoke the command in the background if cvs -q up -dP 1>>cvs_log 2>>cvs_log; then echo "CVS_SUCCESS" >>cvs_log fi & # save the PID of the "if" block above BLKPID=$! # find the PID of the actual command (not the entire block) # (look for parent pid = BLKPID and command = "cvs" ) CMDPID=`ps o ppid,pid,cmd | awk -- "\\$1 ~ /$BLKPID/ && \\$3 ~ /cvs/ {print \\$2}"` # loop until the command ends, if it takes too long, kill it TIMEOUT=60 while ps -p $BLKPID &>/dev/null ; do # check for timeout if [ $TIMEOUT -eq 0 ] ; then # find pids of any children of the command CHILDPID=`ps -A o ppid,pid | awk -- "\\$1 ~ /\$CMDPID/ { print \\$2 }"` # stop the command kill $CMDPID &>/dev/null # stop any children for CHILDPID in $CHILDPID ; do kill $CHILDPID &>/dev/null done # wait for the "if" block to finish wait $BLKPID &>/dev/null # log the timeout echo "CVS_TIMEOUT" >>cvs_log else # wait a bit sleep 1 # decrement TIMEOUT TIMEOUT=$((${TIMEOUT}-1)) fi done if grep -q CVS_SUCCESS cvs_log ; then return 0 ; else return 1 ; fi }