#!/usr/bin/perl -w use strict; my %services = (www => qr/:0050\s/, ssh => qr/:0016\s/, irc => qr/:1A0B\s/, ftp => qr/:0015\s/, ); my $date = `date +"%l:%M:%S"`; my @tcpalive = grep /\b01\s/,`cat /proc/net/tcp`; while (my($key,$REx) = each %services) { $services{$key} = grep /$REx/,@tcpalive } open (FILE, "+>/var/www/web/main.txt") or die $!; print FILE "There are $services{www} web, $services{ftp} ftp, ", "$services{ssh} ssh, and $services{irc} irc connections ", "to this server as of $date\n"; close FILE or die $!;