Sunnmann has asked for the wisdom of the Perl Monks concerning the following question:
I am just looking for some advice on this script, it does work beautifully, but I know there is probably a better way to get this done without as much hassel and probably faster speed in which it completes. To have you understand a bit I will tell you what happened when creating it, so you know why I did this the way I did.
The other day I came here and asked a few people (I am bad with names I am soooooo sorry, but you know who you are and I really really appreciated the help!!) to help me with a problem I had in perl.
I needed to go to over 200 machines, some are WinNT and some are WinXP, and scan the UpdateLog.txt file from McAfee to tell wheather it had been updated or not. If you dont know, NT and XP have different file structures on where they keep this file for McAfee by default. NT uses C:\WINNT\profiles\All Users... and XP uses C:\Documents and Settings\All Users...
I thought the best way would have been to check for what system had what OS and then go from there, but after a bit more thought I remembered that a few of these systems had been upgraded to XP from NT and not a fresh install so they had the NT filesystem intact and no Documents and Settings (sounded wierd to me and still seems wierd).
So instead of checking for the OS I decided my course of action (Mainly because I still suck at Perl) would be to just check if the system had the UpdateLog.txt in C:\WINNT\profiles\All Users... and if it did, it would set the $fname to use the NT file structure and if it did not it would set $fname to use the XP file structure. It then checks for how many days ago the file was modified (found that bit of code on the net).
Here is the code:#!/usr/bin/perl use strict; use warnings; my $fname; my $name; my $ntfile; my $isfile; use file::find; print "Backing up old timesNT.txt... \n"; rename ("timesNT.txt", "bac/timesNT.bac") || die "Cannot rename timesN +T.txt: $!"; open (NODELIST, "nodelistNT.txt") or die "I could not get at nodelist. +txt as input"; open (TIMES, ">>timesNT.txt") or die "I could not open times.txt as ou +tput"; my $time = localtime(time()); print TIMES "$time.--------------------------------------- +------------------------\n\n"; while (<NODELIST>) { chomp; $name=$_; print "$name \n"; $ntfile = "\"\\\\$name\\c\$\\WINNT\\Profiles\\All Users\\Appli +cation Data\\Network Associates\\VirusScan\\UpdateLog.txt\""; # print "$ntfile\n"; $isfile = ""; $isfile = `dir /B $ntfile`; # print "$isfile\n"; if ($isfile ne "") { $fname = "//$name/c\$/WINNT/Profiles/All Users/App +lication Data/Network Associates/VirusScan/UpdateLog.txt"; print "This system is NT!!!!!!\n"; STUFF(); } else { $fname = "//$name/c\$/Documents and Settings/All U +sers/Application Data/Network Associates/VirusScan/UpdateLog.txt"; print "This system is XP!!!!!!!!!!!!!!!!!\n"; STUFF(); } } close NODELIST; close TIMES; sub STUFF { my $modded = -M $fname; # print TIMES "Server Name: $name\n"; # print TIMES "$modded\n\n"; if ($modded >= 2) { print TIMES "Server Name: $name\n"; print TIMES "$modded\n\n"; } }
Please let me know what you think, is there an easier way to get done what I have?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Has McAfee UpdateLog.txt been updated recently
by NetWallah (Canon) on Dec 22, 2006 at 01:01 UTC | |
by Marza (Vicar) on Dec 22, 2006 at 04:12 UTC | |
|
Re: Has McAfee UpdateLog.txt been updated recently
by GrandFather (Saint) on Dec 22, 2006 at 00:31 UTC | |
by Sunnmann (Acolyte) on Dec 22, 2006 at 01:15 UTC | |
by GrandFather (Saint) on Dec 22, 2006 at 01:29 UTC | |
by calin (Deacon) on Dec 22, 2006 at 11:27 UTC |