djw has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my(@tcpstatus,@tcpalive,$date,$line); my($ftp,$www,$ssh,$irc); $date = `date +"%l:%M:%S"`; $ftp = 0; $www = 0; $ssh = 0; $irc = 0; @tcpalive = (); ############################ # get current tcp status # ############################ @tcpstatus = `cat /proc/net/tcp`; ############################ # grab only the ones that # # are marked "Active" (01) # # and put them into new # # array # ############################ foreach (@tcpstatus) { while (/\b01\s/) { push(@tcpalive,$_); last; } } ############################ # ugly. I know there has # # got to be a better way # # to get this done. Step # # through new array and # # add how many times each # # service is found # ############################ foreach (@tcpalive) { while (/:0050\s/) { $www++; last; } } foreach (@tcpalive) { while (/:0016\s/) { $ssh++; last; } } foreach (@tcpalive) { while (/:1A0B\s/) { $irc++; last; } } foreach (@tcpalive) { while (/:0015\s/) { $ftp++; last; } } ############################ # print this out to a file # # used for server side # # includes # ############################ open (FILE, "+>/var/www/web/main.txt"); print FILE "There are $www web, $ftp ftp, $ssh ssh, and $irc irc conne +ctions to this server as of $date\n"; close FILE;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: efficiency & style
by tye (Sage) on Sep 23, 2000 at 11:21 UTC | |
by tilly (Archbishop) on Sep 23, 2000 at 12:04 UTC | |
by dchetlin (Friar) on Sep 23, 2000 at 14:13 UTC | |
by tye (Sage) on Sep 23, 2000 at 18:52 UTC | |
by tilly (Archbishop) on Sep 23, 2000 at 20:26 UTC | |
by djw (Vicar) on Sep 24, 2000 at 19:04 UTC | |
Stolen thunder
by dchetlin (Friar) on Sep 23, 2000 at 11:45 UTC | |
Re (tilly) 1: efficiency & style
by tilly (Archbishop) on Sep 23, 2000 at 12:33 UTC | |
Re: efficiency & style
by gregorovius (Friar) on Sep 23, 2000 at 12:03 UTC |