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?


In reply to Has McAfee UpdateLog.txt been updated recently by Sunnmann

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.