#!/usr/local/bin/perl -w use strict; $|=1; use IO::Socket::INET; if (scalar @ARGV < 2) { die usage(); } my($filenam,$portnum,$OUTDIR,$OUTFIL,$outfil,$begin,$MySocket,$text); my($YEAR,$MO,$DAY,$HOUR,$MIN,$MONTH,$yr,$timeofday,$damoyr); $filenam = $ARGV[0]; $portnum = $ARGV[1]; my(@NOW) = localtime(); ($YEAR,$MO,$DAY,$HOUR,$MIN) = @NOW[5,4,3,2,1]; $MONTH = $MO + 1; $YEAR = $YEAR + 1900; $yr = $YEAR - 2000; $damoyr = sprintf("%02d/%02d/%02d",$MONTH,$DAY,$yr); $timeofday = sprintf("%02d:%02d",$HOUR,$MIN); $OUTDIR = "/active/"; $outfil = $OUTDIR . $filenam; print "outfile is $outfil\n"; open(OUTFIL,">$outfil"); # Create a new socket $MySocket=new IO::Socket::INET->new(LocalPort=>$portnum, Proto=>'udp'); $begin="\nStarting UDP Receiver $damoyr $timeofday\n"; print OUTFIL "$begin"; # Keep receiving messages; while(1) { $MySocket->recv($text,128); print OUTFIL "$text#$damoyr $timeofday\n"; print "$text#$damoyr $timeofday\n"; } close(OUTFIL); sub usage { my $usage = < - filename is name of log file in the logging directory - portnum is the UDP port number to listen to EOF return $usage; }