Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grabbing certain lines from a file that is generated

Status
Not open for further replies.

Sunnmann

Technical User
Oct 11, 2003
10
US
OK, so I have this script that I created and thought it was working fine. It starts with 1 input file and ultimately creates output files that are used as inputs later and then in the end creates a final output file that is supposed to tell em what PC's have a certain hotfix using another input on that one.

what we have so far:
TWSSRVINFO.PL (The script consists of 3 parts. running srvinfo.exe to find specs on a system over a network (syntax is srvinfo -ns [system]. The -ns is for no services. Taking those specs and finding only the server name and what hotfixes it has. Taking the last information and comparing to another user created file to see which systems DO NOT have a specified hotfix.)

TWSPCINFO.txt (User created first input used.)

TWSSRVINFO.txt (first output created, this is then used as input on the second part.)

TWSHOTFIXES.txt (second output created, which is then used as one of the inputs for the 3rd and last part of the script.)

HOTLIST.txt (User created input that has what hotfixes you are looking for.)

TWSNEED.txt (Final output that shows what TWS DO NOT have the certain hotfixes, so you know which ones still need it.)

Here is what I thought to be my final perl product (hope this all fits):

#!/usr/local/bin/perl

#Team Workstation srvinfo Section

print "Backing up old twssrvinfo.txt... \n";
rename ("C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twssrvinfo.txt", "C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\bac\\twssrvinfo.bac") || die "Cannot rename twssrvinfo.txt: $!";

print "Starting Server hotfixes finder \n";

open (TWSPCINFO, "C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twspcinfo.txt") or die "I could not get at twspcinfo.txt as input";
open (TWSSRVINFO, ">>C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twssrvinfo.txt") or die "I could not open twssrvinfo.txt as output";

my $time;
$time = localtime(time());
print TWSSRVINFO "$time.---------------------------------------------------------------\n\n";

while (<TWSPCINFO>)
{
chomp;
my $srv;
$srv=$_;
print &quot;$srv \n&quot;;
my $result;
$result = `srvinfo -ns \\\\$srv`;
print TWSSRVINFO &quot;Server Name: $srv\n&quot;;
print TWSSRVINFO &quot;$result\n&quot;;
print TWSSRVINFO &quot;\n===========================\n\n&quot;;
}
close TWSPCINFO;
close TWSSRVINFO;

#Team Workstation hotfixes Section

print &quot;Backing up old twshotfixes.txt... \n&quot;;
rename (&quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twshotfixes.txt&quot;, &quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\bac\\twshotfixes.bac&quot;) || die &quot;Cannot rename twshotfixes.txt: $!&quot;;

open (TWSINPUT, &quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twssrvinfo.txt&quot;) or die &quot;I could not open twssrvinfo.txt&quot;;
($WAIT_NAME, $WAIT_FIX, $WAIT_DRIVE) = (0,1,2);
open (TWSOUTPUT, &quot;>>C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twshotfixes.txt&quot;) or die &quot;I could not open twshotfixed.txt&quot;;

$CUR_STATE = $WAIT_NAME;
@FIXES;

while(<TWSINPUT>)
{
if($CUR_STATE == $WAIT_NAME && /^Server\ Name\:\ (.+)\n/)
{
print TWSOUTPUT &quot;\n&quot;;
print TWSOUTPUT &quot;$1&quot;;
chomp;
$CUR_STATE = $WAIT_FIX;
}
#if(/^Server\ Name\:\ (.+)\n/)
#{
# print TWSOUTPUT &quot;$1&quot;;
# $CUR_STATE = $WAIT_FIX;
#}
elsif($CUR_STATE == $WAIT_FIX && /^Network\ Error\ (.+)\n/)
{
print TWSOUTPUT &quot; $1\n&quot;;
chomp;
$CUR_STATE = $WAIT_NAME;
}
elsif($CUR_STATE == $WAIT_FIX && /^Hotfixes/)
{
$CUR_STATE = $WAIT_DRIVE;
}
elsif($CUR_STATE == $WAIT_DRIVE && /^Drive/)
{
$CUR_STATE = $WAIT_NAME;
print TWSOUTPUT &quot;@FIXES\n&quot;;
chomp;
}
elsif($CUR_STATE == $WAIT_DRIVE && /^Network/)
{
$CUR_STATE = $WAIT_NAME;
print TWSOUTPUT &quot;@FIXES\n&quot;;
chomp;
}
elsif($CUR_STATE == $WAIT_DRIVE && /^Protocols/)
{
$CUR_STATE = $WAIT_NAME;
print TWSOUTPUT &quot;@FIXES\n&quot;;
chomp;
}
elsif($CUR_STATE == $WAIT_DRIVE && /\[(.+)\]\:/)
{
push (@FIXES, &quot;,$1&quot;);
}
else
{
# die &quot;INVALID DATA:$_&quot;;
}
}

close TWSINPUT;
close TWSOUTPUT;

#Team Workstation needed hotfixes Section

print &quot;Backing up old twsneed.txt... \n&quot;;
rename (&quot;twsneed.txt&quot;, &quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\bac\\twsneed.bac&quot;) || die &quot;Cannot rename twsneed.txt: $!&quot;;

print &quot;looking for Team Workstations without listed hotfixes. Please be patient.\n&quot;;

open (HOTLIST, &quot;hotlist.txt&quot;) or die &quot;I could not open hotlist as input&quot;;
open (TWSNEEDLIST, &quot;>>twsneed.txt&quot;) or die &quot;I cannot open twsneed.txt as output&quot;;

my $time;
$time = localtime(time());
print TWSNEEDLIST &quot;$time.---------------------------------------------------------------\n\n&quot;;

while(<HOTLIST>)
{
chomp;
my $fix;
$fix=$_;
print &quot;$fix \n&quot;;
print TWSNEEDLIST &quot;hotfix: $fix \n\n&quot;;
my $hots;
$hots = `findstr -v $fix C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twshotfixes.txt`;
print TWSNEEDLIST &quot;$hots\n\n&quot;;
print TWSNEEDLIST &quot;==============================================================================\n\n&quot;;
}

close HOTLIST;
close TWSNEEDLIST;

Now that you see that I will show you what my other inputs look like.

TWSPCINFO.txt:
rrc7850-desk
rrc7299-desk
rrc7793-desk

TWSSRVIFO.txt:
Thu Jan 1 11:03:15 2004.---------------------------------------------------------------

Server Name: rrc7850-desk

Server Name: rrc7850-desk
Security: Users
Registered Owner: (omited)
Registered Organization: (Omited)
ProductID: (Omited)
Original Install Date: Sat Nov 29 11:09:41 2003
Base Source Path: C:\drivers\i386
Service Pack Source Path: D:Version: 5.1
Build: (omited)
Current Type: Uniprocessor Free
Product Name: Microsoft Windows XP
Product Options: Professional
HAL.DLL is (omited)
PDC: (omited)
Domain: (omited)
Domain Guid: (omited)
DNS Forest Name: (omited)
PDC Site Name: (omited)
Computer Site Name: (omited)
CPU[0]: x86 Family 6 Model 8 Stepping 6: 930 MHz
System BIOS Date: 09/21/00
System BIOS Version: IBM - 1010, IBM BIOS Ver PIKT24.0
Hotfixes:
Windows XP:
SP2
[KB823559]: Installed on 11/29/2003 by Administrator
[KB824146] Installed on 11/29/2003 by Administrator
[Q323255]: Installed on 4/7/2003 by Administrator
[Q328310]: Installed on 4/7/2003 by Administrator
[Q329390]: Installed on 4/7/2003 by Administrator
[Q331953]: Installed on 11/29/2003 by Administrator
[Q810097]: Installed on 4/7/2003 by Administrator
[Q810833]: Installed on 11/29/2003 by Administrator
[Q815021]: Installed on 11/29/2003 by Administrator
[Q816556]: Installed on 11/29/2003 by Administrator
[Q817606]: Installed on 11/29/2003 by Administrator
Windows Media Player:
wm817787
[FileList]: Installed on ??/??/?? by Unknown
Drive: [FileSys] [ Size ] [ Free ] [ Used ]
C$ NTFS 19470 14310 5160
Network Card [0]: IBM 10/100 EtherJet PCI Management Adapter
IP Address(es): (omited)
MAC Address: (omited)
Protocols:
Layer 2 Tunneling Protocol
Remote Access NDIS WAN Driver
Point to Point Tunneling Protocol
WINS Client(TCP/IP) Protocol
Internet Protocol (TCP/IP)
Point to Point Protocol Over Ethernet
NDIS Usermode I/O Protocol
Message-oriented TCP/IP Protocol (SMB session)
System Up Time: 0 Days, 6 Hr, 54 Min, 51 Sec


===========================

Server Name: rrc7299-desk

Server Name: rrc7299-desk
Security: Users
Registered Owner: (omited)
Registered Organization: (omited)
ProductID: (omited)
Original Install Date: Fri Jun 27 11:09:30 2003
Base Source Path: (omited)
Service Pack Source Path: c:\push
Version: 5.0
Build: 2195, Service Pack 4
Current Type: Uniprocessor Free
Product Name: Microsoft Windows 2000
Product Options: Professional
HAL.DLL is (omited)
PDC: (omited)
Domain: (omited)
Domain Guid: (omited)
DNS Forest Name: (omited)
PDC Site Name: (omited)
Computer Site Name: (omited)
CPU[0]: x86 Family 6 Model 8 Stepping 6: 930 MHz
System BIOS Date: 09/21/00
System BIOS Version: IBM BIOS Ver PIKT24.0
Hotfixes:
Windows Media Player:
wm320920.1
[FileList]: Installed on ??/??/?? by Unknown
Windows 2000:
SP4
[Q327194]: Installed on 12/27/2003 by SYSTEM
SP5
[KB823559]: Installed on 12/27/2003 by SYSTEM
[KB823980]: Installed on 8/7/2003 by jmdykstr
[KB824146]: Installed on 9/20/2003 by jmdykstr
[KB828035]: Installed on 12/1/2003 by SYSTEM
[KB828749]: Installed on 12/3/2003 by SYSTEM
DataAccess:
Q323264
Q329414-25
Drive: [FileSys] [ Size ] [ Free ] [ Used ]
C$ NTFS 8229 3735 4494
Network Card [0]: IBM 10/100 EtherJet PCI Management Adapter
IP Address(es): (omited)
MAC Address: (omited)
Protocols:
Message-oriented TCP/IP Protocol (SMB session)
Remote Access NDIS WAN Driver
Point to Point Tunneling Protocol
Layer 2 Tunneling Protocol
WINS Client(TCP/IP) Protocol
Internet Protocol (TCP/IP)
NDIS Usermode I/O Protocol
System Up Time: 2 Days, 5 Hr, 8 Min, 46 Sec


===========================

Server Name: rrc7793-desk

Server Name: rrc7793-desk
Security: Users
Registered Owner: (omited)
Registered Organization: (omited)
ProductID: (omited)
Original Install Date: Fri Jun 27 11:09:30 2003
Base Source Path: (omited)
Service Pack Source Path: D:Version: 5.0
Build: 2195, Service Pack 3
Current Type: Uniprocessor Free
Product Name: Microsoft Windows 2000
Product Options: Professional
HAL.DLL is (omited)
PDC: (omited)
Domain: (omited)
Domain Guid: (omited)
DNS Forest Name: (omited)
PDC Site Name: (omited)
Computer Site Name: (omited)
CPU[0]: x86 Family 6 Model 8 Stepping 6: 930 MHz
System BIOS Date: 09/21/00
System BIOS Version: IBM BIOS Ver PIKT24.0
Hotfixes:
Windows Media Player:
wm320920.1
[FileList]: Installed on ??/??/?? by Unknown
Windows 2000:
SP4
[Q323255]: Installed on 6/27/2003 by Administrator
[Q326830]: Installed on 6/27/2003 by Administrator
[Q328310] Installed on 6/27/2003 by Administrator
[Q331953]: Installed on 6/27/2003 by Administrator
[Q810030]: Installed on 6/27/2003 by Administrator
[Q810833]: Installed on 6/27/2003 by Administrator
[Q815021]: Installed on 8/21/2003 by
SP5
[KB823980]: Installed on 8/7/2003 by
[KB824146]: Installed on 9/20/2003 by
[KB828035]: Installed on 11/26/2003 by SYSTEM
[KB828749]: Installed on 12/3/2003 by SYSTEM
DataAccess:
Q323264
Q329414-25
Drive: [FileSys] [ Size ] [ Free ] [ Used ]
C$ NTFS 11006 6149 4857
G$ FAT32 4111 2307 1804
Network Card [0]: IBM 10/100 EtherJet PCI Management Adapter
IP Address(es): (omited)
MAC Address: (omited)
Protocols:
Message-oriented TCP/IP Protocol (SMB session)
Remote Access NDIS WAN Driver
Point to Point Tunneling Protocol
Layer 2 Tunneling Protocol
WINS Client(TCP/IP) Protocol
Internet Protocol (TCP/IP)
System Up Time: 0 Days, 9 Hr, 44 Min, 25 Sec


===========================

TWSHOTFIXES.txt

rrc7850-desk,KB823559 ,KB824146 ,Q323255 ,Q328310 ,Q329390 ,Q331953 ,Q810097 ,Q810833 ,Q815021 ,Q816556 ,Q817606 ,FileList

rrc7299-desk,KB823559 ,KB824146 ,Q323255 ,Q328310 ,Q329390 ,Q331953 ,Q810097 ,Q810833 ,Q815021 ,Q816556 ,Q817606 ,FileList ,FileList ,Q327194 ,KB823559 ,KB823980 ,KB824146 ,KB828035 ,KB828749

rrc7793-desk,KB823559 ,KB824146 ,Q323255 ,Q328310 ,Q329390 ,Q331953 ,Q810097 ,Q810833 ,Q815021 ,Q816556 ,Q817606 ,FileList ,FileList ,Q327194 ,KB823559 ,KB823980 ,KB824146 ,KB828035 ,KB828749 ,FileList ,Q323255 ,Q326830 ,Q328310 ,Q331953 ,Q810030 ,Q810833 ,Q815021 ,KB823980 ,KB824146 ,KB828035 ,KB828749

HOTLIST.txt:
828035
828749
815021

TWSNEED.txt

Thu Jan 1 11:16:18 2004.---------------------------------------------------------------

hotfix: 828035


rrc7850-desk,KB823559 ,KB824146 ,Q323255 ,Q328310 ,Q329390 ,Q331953 ,Q810097 ,Q810833 ,Q815021 ,Q816556 ,Q817606 ,FileList




==============================================================================

hotfix: 828749


rrc7850-desk,KB823559 ,KB824146 ,Q323255 ,Q328310 ,Q329390 ,Q331953 ,Q810097 ,Q810833 ,Q815021 ,Q816556 ,Q817606 ,FileList




==============================================================================

hotfix: 815021






==============================================================================


Of course anythign that could possibly be confidential to Intel has been omited. I also added in bold red the information I want to grab from the TWSSRVINFO.txt file.

OK, now you have all the text files that are created and what i see when it is finalized inall areas.

The problem I am having is that TWSHOTFIXES seems to be duplcating and not chomping something off. This means when the last one runs, it will not show me a system that needs the hotfixes because the files say it does, and that is only because it is retaining the information from the start.

I have tried adding a chomp to the beginning of the while loop and that does not work at all, I just get a sheet with the hotfixes name on it in the end.

Anyone out there that can take a look at thisand tell me what I am doing wrong? I am so lost now, it took me forever to get this far and now I feel dumb cause i cant figure this out.

(FYI: the script is written like it is because I am new, I did not try to condense it to make it shorter, I just wanted to see what each part looks like when it is done and then maybe in about a hundred years when I am proficient in perl I will condense it down if it is possible)

I want to thank you gusy in advance if you can help me. (If this script works, I save hours of time manually going System by system to see if someone has installed a patch)
 
You want any help on this one, you may want to make it easier to read

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I am sorry, I thought I did. I will give it another go and see if that works....(once I get home)
 
I am sorry I never re posted this question. But trhere was really no other way for me to show you than what i did. I bolded out ost sectioned and tried to keep it so you would see it how I do, and also see it in its raw from. If I would have shortened it so that you did not have to scroll over to see words, then it would be code all squinched together with lines where they are not supposed to be. Sorry I could not accomidate and make it look super spiffy in a way i could nto figure out.

But I did find the fix to my problem and it was pretty easy.

If anyone wants to know what I found that fixed this problem:

The problem I was having is that @FIXES was not being emptied out. It was actually quite simple and since I am new took me forever to find. SO I added in a line of @FIXES=&quot;&quot;; and it fixed the issue. I also took out all of the chomps as I learned that is not what I was looking for.

here is what that part of the script looks like now. The part I fixed is now in BOLD RED

#Team Workstation hotfixes Section

print &quot;Backing up old twshotfixes.txt... \n&quot;;
rename (&quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twshotfixes.txt&quot;, &quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\bac\\ twshotfixes.bac&quot;) || die &quot;Cannot rename twshotfixes.txt: $!&quot;;

open (TWSINPUT, &quot;C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twssrvinfo.txt&quot;) or die &quot;I could not open twssrvinfo.txt&quot;;
($WAIT_NAME, $WAIT_FIX, $WAIT_DRIVE) = (0,1,2);
open (TWSOUTPUT, &quot;>>C\:\\perl_scripts\\srvinfopc\\txtfiles\\TWS\\twshotfixes.txt&quot;) or die &quot;I could not open twshotfixed.txt&quot;;

$CUR_STATE = $WAIT_NAME;
@FIXES;

while(<TWSINPUT>)
{
if($CUR_STATE == $WAIT_NAME && /^Server\ Name\:\ (.+)\n/)
{
print TWSOUTPUT &quot;\n&quot;;
print TWSOUTPUT &quot;$1&quot;;
$CUR_STATE = $WAIT_FIX;
}
elsif($CUR_STATE == $WAIT_FIX && /^Network\ Error\ (.+)\n/)
{
print TWSOUTPUT &quot; $1\n&quot;;
$CUR_STATE = $WAIT_NAME;
}
elsif($CUR_STATE == $WAIT_FIX && /^Hotfixes/)
{
$CUR_STATE = $WAIT_DRIVE;
@FIXES=&quot;&quot;;
}
elsif($CUR_STATE == $WAIT_DRIVE && /^Drive/)
{
$CUR_STATE = $WAIT_NAME;
print TWSOUTPUT &quot;@FIXES\n&quot;;
}
elsif($CUR_STATE == $WAIT_DRIVE && /^Network/)
{
$CUR_STATE = $WAIT_NAME;
print TWSOUTPUT &quot;@FIXES\n&quot;;
}
elsif($CUR_STATE == $WAIT_DRIVE && /^Protocols/)
{
$CUR_STATE = $WAIT_NAME;
print TWSOUTPUT &quot;@FIXES\n&quot;;
}
elsif($CUR_STATE == $WAIT_DRIVE && /\[(.+)\]\:/)
{
push (@FIXES, &quot;,$1&quot;);
}
else
{
# die &quot;INVALID DATA:$_&quot;;
}
}

close TWSINPUT;
close TWSOUTPUT;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top