If timeout is zero, set it to 1^6. That should be good enough.
Don't filter output through sed, this makes it impossible to kill the
"tail" process.
Catch the tail PID, and kill it on exit.
Trap on signals, not on normal exit.
Duplicate code in trap for normal exit. This ensures that the code is
only executed once.
extra="-f $OPTARG"
;;
t) timeout="$OPTARG"
+ [ "$timout" = "0" ] && timeout=1000000
;;
u) condition="(User-Name == $OPTARG)"
;;
cp /dev/null $outfile
chmod g+w $outfile
+TAILPID=$$
+
#
# Set the trap to clean up on exit and any interrupts.
#
-trap '$radmin -e "debug condition" -e "debug file"; rm -f $outfile; exit 0' 0 1 2 15
+trap '$radmin -e "debug condition" -e "debug file"; rm -f $outfile;kill -TERM $TAILPID;exit 0' 1 2 15
#
# Set the debug condition
#
# Print the output, and wait for "timeout". Then, stop printing.
#
-(tail -f $outfile | sed 's/^.*Debug: //') &
+tail -f $outfile &
+TAILPID=$!
sleep $timeout
-kill -INT %1
+kill -TERM $TAILPID
+$radmin -e "debug condition" -e "debug file"
+rm -f $outfile