# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
-# Copyright (C) 2009 Alan DeKok <aland@deployingradius.com>
+# Copyright (C) 2009 Network RADIUS SARL <info@networkradius.com>
#
######################################################################
#
extra=
condition=1
-timeout=10
+timeout=60
while getopts 'd:c:i:I:f:t:u:' OPTION
do
case $OPTION in
c) condition="$OPTARG"
;;
- d) [ "$extra" == "" ] || usage
+ d) [ "$extra" = "" ] || usage
extra="-d $OPTARG"
;;
i) condition="(Packet-Src-IP-Address == $OPTARG)"
;;
I) condition="(Packet-Src-IPv6-Address == $OPTARG)"
;;
- f) [ "$extra" == "" ] || usage
+ f) [ "$extra" = "" ] || usage
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