browserice
Technical User
I am coding my first Perl script. It reads an input file produced from a tivoli "wmonpln -l" command and redirecting it to another file but in a comma seperated record to be used by other sets of tools.
1) The input (I don't know how) should be from the pipe. Right now, I put down a file just for the testing purposes but need it to be from a pipe (xxxx >myperl.pl).
2) if there are 9 fields, then comma seperate all fields into a string and output it
3) if there are 10 fields, then 2 fields need to be combined and then comma seperate all fields into a string to then output it
Now with this input info, here is my perl script below. When I ran it, it displayed in console, lines with one long integer (I don't know why). I added print cmds for debuging infos but I still have no clues :
#!/usr/bin/env perl
#
#====================================================================================
# name : CleanPlanOutput.pl
# version : Beta 1.0
# language: Perl
# Created by : me
# Created on : Aug-20, 2006
# Description : takes the wmonplan output and re-outputs it in comma seperated fields
# to be used by any other scripts. Takes in account the status that can
# be 2 words or not.
#=======================================================================================================================================================================
#<-----PlanID------> ReturnCode <--Status------> <-------PlanName-----------------------------------------------------------> <----StartedAt----> <------EndedAt----->
#1155772582033163865 0 Canceled Pending UK_REM_EMD_ms_std_hotfix_sequence_NET_part1_ALL_2006-08-15@08/17/06 01:56:22 2006-08-17 01:56:22 2006-08-18 01:58:21
#Field#0 1 2 3 4 5 6 7 8 9
#1155772659085890842 0 Canceled UK_REM_EMD_ms_std_hotfix_sequence_NET_part2_ALL_2006-08-15@08/17/06 01:57:39 2006-08-17 01:57:39 2006-08-18 02:00:34
#Field#0 1 2 3 4 5 6 7 8
#=======================================================================================================================================================================
#initializations
#open input file
open(INFILE,"wmonpln.tmp") or die "Cannot open CleanPlanOutput input!";
#open output file
open(OUTFILE,">CleanPlanOutput.pl.tmp") or die "Cannot open CleanPlanOutput output!";
#open output log file
open(LOGFILE,">CleanPlanOutput.pl.log") or die "Cannot open CleanPlanOutput Log file!";
print "Starting...\n";
#while input file not empty
while (<INFILE>) {
# reads a record
my $InputRec=<INFILE>;
print "reading:"+$InputRec+"\n";
# parse fields into array
@fields=split(" ",$InputRec);
# is there 9 fields ?
if ( @fields==9 ) {
# then status should be one word only, get all 9 fields
print "9 fields found\n";
$OutputRec=@fields[0]+","+@fields[1]+","+@fields[2]+","+@fields[3]+@fields[4]+",";
$OutputRec=$OutputRec+@fields[5]+@fields[6]+","+@fields[7]+@fields[8];
} elsif ( @fields==10 && @fields[3]=="Pending" ) {
# otherwise, is there 10 fields ?
# then status should be 2 words, get all 10 fields
print "10 fields found\n";
$OutputRec=@fields[0]+","+@fields[1]+","+@fields[2]+@fields[3]+",";
$OutputRec=$OutputRec+@fields[4]+@fields[5]+","+@fields[6]+@fields[7]+",";
$OutputRec=$OutputRec+@fields[8]+@fields[9];
} else {
# otherwise, we have a faulty record ?
print "non standard record found\n";
$OutputRec="";
print LOGFILE $InputRec;
}
# output the record in right order
print OUTFILE $OutputRec;
}
#close input
close INFILE;
#close output
close OUTFILE;
close LOGFILE;
1) The input (I don't know how) should be from the pipe. Right now, I put down a file just for the testing purposes but need it to be from a pipe (xxxx >myperl.pl).
2) if there are 9 fields, then comma seperate all fields into a string and output it
3) if there are 10 fields, then 2 fields need to be combined and then comma seperate all fields into a string to then output it
Now with this input info, here is my perl script below. When I ran it, it displayed in console, lines with one long integer (I don't know why). I added print cmds for debuging infos but I still have no clues :
#!/usr/bin/env perl
#
#====================================================================================
# name : CleanPlanOutput.pl
# version : Beta 1.0
# language: Perl
# Created by : me
# Created on : Aug-20, 2006
# Description : takes the wmonplan output and re-outputs it in comma seperated fields
# to be used by any other scripts. Takes in account the status that can
# be 2 words or not.
#=======================================================================================================================================================================
#<-----PlanID------> ReturnCode <--Status------> <-------PlanName-----------------------------------------------------------> <----StartedAt----> <------EndedAt----->
#1155772582033163865 0 Canceled Pending UK_REM_EMD_ms_std_hotfix_sequence_NET_part1_ALL_2006-08-15@08/17/06 01:56:22 2006-08-17 01:56:22 2006-08-18 01:58:21
#Field#0 1 2 3 4 5 6 7 8 9
#1155772659085890842 0 Canceled UK_REM_EMD_ms_std_hotfix_sequence_NET_part2_ALL_2006-08-15@08/17/06 01:57:39 2006-08-17 01:57:39 2006-08-18 02:00:34
#Field#0 1 2 3 4 5 6 7 8
#=======================================================================================================================================================================
#initializations
#open input file
open(INFILE,"wmonpln.tmp") or die "Cannot open CleanPlanOutput input!";
#open output file
open(OUTFILE,">CleanPlanOutput.pl.tmp") or die "Cannot open CleanPlanOutput output!";
#open output log file
open(LOGFILE,">CleanPlanOutput.pl.log") or die "Cannot open CleanPlanOutput Log file!";
print "Starting...\n";
#while input file not empty
while (<INFILE>) {
# reads a record
my $InputRec=<INFILE>;
print "reading:"+$InputRec+"\n";
# parse fields into array
@fields=split(" ",$InputRec);
# is there 9 fields ?
if ( @fields==9 ) {
# then status should be one word only, get all 9 fields
print "9 fields found\n";
$OutputRec=@fields[0]+","+@fields[1]+","+@fields[2]+","+@fields[3]+@fields[4]+",";
$OutputRec=$OutputRec+@fields[5]+@fields[6]+","+@fields[7]+@fields[8];
} elsif ( @fields==10 && @fields[3]=="Pending" ) {
# otherwise, is there 10 fields ?
# then status should be 2 words, get all 10 fields
print "10 fields found\n";
$OutputRec=@fields[0]+","+@fields[1]+","+@fields[2]+@fields[3]+",";
$OutputRec=$OutputRec+@fields[4]+@fields[5]+","+@fields[6]+@fields[7]+",";
$OutputRec=$OutputRec+@fields[8]+@fields[9];
} else {
# otherwise, we have a faulty record ?
print "non standard record found\n";
$OutputRec="";
print LOGFILE $InputRec;
}
# output the record in right order
print OUTFILE $OutputRec;
}
#close input
close INFILE;
#close output
close OUTFILE;
close LOGFILE;