blackadder has asked for the wisdom of the Perl Monks concerning the following question:
here is the code
# # # # # # use vars qw/%Data %Tk %Info/; use Tk; use Win32; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Tk{main} = MainWindow->new (-background => 'white', -title=> 'WinBcp +Check v6.0'); $Tk{main}->geometry('400x130'); $Tk{top_frame} = $Tk{main}->Frame->pack(qw/-side top -fill x/); $Tk{source_box} = $Tk{top_frame}->Label(-text=>"Hosts : ")->pack(qw/-s +ide left -padx 10 -pady 10/); $Tk{source_entry} = $Tk{top_frame}->Entry(-width=>40, -textvariable=> +\ $Data{source})->pack(qw/-side right -fill both -padx 10 -pady 10 -e +xpand 1/); $Tk{middle_frame} = $Tk{main}->Frame->pack(qw/-side top -fill x/); $Tk{middle_box} = $Tk{middle_frame}->Label(-text=>"Path : ")->pack(qw +/-side left -padx 10 -pady 10/); $Tk{middle_entry} = $Tk{middle_frame}->Entry(-width=>40, -textvariable +=> \ $Data{path})->pack(qw/-side right -fill both -padx 10 -pady 10 - +expand 1/); $Tk{bottom_frame} = $Tk{main}->Frame->pack(qw/-side top -fill x/); $Tk{go_buttn} = $Tk{bottom_frame}->Button( -text= +>'GO!', -borde +rwidth=>5, -width +=>60, -comma +nd=>sub { + &check_process; + Win32::MsgBox("Operation has completed +successfully, Please save your xls file - be aware of save path if yo +u are using your admin account.", 0,$0); + } )->pac +k(qw/-side bottom -padx 10 -pady 10/); sub check_process { my @DB_info; $Data{analyst} = Win32::LoginName(); $Data{app_sync_dir} = 'c$\program files\common files\samanchi sysa +dmin\log\ApplicationSynchronizer'; open (LST, "$Data{source}") || &error_display($Data{source}); chomp (my @work_file=<LST>); close (LST); for (@work_file) { next if ($_ =~ /^\s*$/); my $data = {}; ($data->{bu}, $data->{group}, $data->{function}, $data->{source_id}, $data->{source_pc}, $data->{target_pc},) = split (/,/,$_); push (@DB_info, $data); } my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Wi +n32::OLE->new('Excel.Application'); print "\nStarting up Excel.....\n"; $Excel->{Visible} = 1; my $Book = $Excel->Workbooks->Add; my $Sheet1 = $Book->Worksheets(1); $Sheet1->Range ("A:F")->{ColumnWidth}=30; $Sheet1->Cells(1,1)->{value}= "Technical Support Person : ".$Data{ +analyst}; $Sheet1->Cells(2,1)->Font->{FontStyle}= 'bold'; $Sheet1->Cells(2,1)->{value}= "Target Machine"; $Sheet1->Cells(2,2)->Font->{FontStyle}= 'bold'; $Sheet1->Cells(2,2)->{value}= "Business Unit"; $Sheet1->Cells(2,3)->Font->{FontStyle}= 'bold'; $Sheet1->Cells(2,3)->{value}= "Groups"; $Sheet1->Cells(2,4)->Font->{FontStyle}= 'bold'; $Sheet1->Cells(2,4)->{value}= "Function"; $Sheet1->Cells(2,5)->Font->{FontStyle}= 'bold'; $Sheet1->Cells(2,5)->{value}= "WinBcp Status"; $Sheet1->Cells(2,6)->Font->{FontStyle}= 'bold'; $Sheet1->Cells(2,6)->{value}= "Information"; my $row = 3; my $col; for my $info (@DB_info) { $col = 1; print "\n----------------------------------------------------- +-------------------\n"; my $target_dir = "\\\\".$info->{target_pc}."\\".$Data{app_sync +_dir}; print "\n$info->{target_pc} ($info->{bu}, $info->{group}, $inf +o->{function})\n"; $Sheet1->Cells($row, $col++)->{value}= "$info->{target_pc}"; $Sheet1->Cells($row, $col++)->{value}= "$info->{bu}"; $Sheet1->Cells($row, $col++)->{value}= "$info->{group}"; $Sheet1->Cells($row, $col++)->{value}= "$info->{function}"; my $rep = `ping $info->{target_pc} -n 1`; if ($rep =~ /reply/i) { if (-e $target_dir) { print "WinBcp operation status : "; my $hist_log = $target_dir.'\History.log'; open(APPSYNC, $hist_log) || warn "\n$_ : No log file w +as found\n"; chomp(my @status = <APPSYNC>); close (APPSYNC); $status[$#status] =~ /(\w+)\s*\[BATCHMODE\](.+)\s*$/; print "$1\n$2\n"; if ($1 !~ /^\s*$/) { $Sheet1->Cells($row, $col++)->{value}= "$1"; $Sheet1->Cells($row++, $col++)->{value}= "$2"; } else { $Sheet1->Cells($row++, $col++)->{value}= 'Unknown' +; } } else { print " : No ApplicationSynchronizer folder was detect +ed.\n"; $Sheet1->Cells($row++, $col++)->{value}= 'No Applicati +onSynchronizer folder was detected'; } } else { print "\n$info->{target_pc} : PC Down\n"; $Sheet1->Cells($row++, $col++)->{value}= 'PC Down'; } } print "\n\n____________________________Completed the List_________ +___________________\n\n\n\n"; $Book->SaveAs ("$Data{path}"); } sub error_display { my (@input) = @_; Win32::MsgBox("$!\n\n@input\n",0x00000000 |0x00000010|0x00000000," +$0 : Operation Failed"); exit 1; } END { print "\n\n******************************************************* +**********\n"; print "\n\n\t\t\tScript by : Blackadder \n"; print "\n\n\t\t\tDate : September 2004 \n"; print "\n\n******************************************************* +**********\n"; } Tk::MainLoop; exit 1;
janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl2Exe converting my scripts to Japanese
by TimToady (Parson) on Sep 17, 2004 at 18:11 UTC | |
|
Re: Perl2Exe converting my scripts to Japanese
by Courage (Parson) on Sep 16, 2004 at 14:23 UTC | |
by blackadder (Hermit) on Sep 17, 2004 at 14:02 UTC | |
by Courage (Parson) on Sep 18, 2004 at 06:44 UTC | |
by blackadder (Hermit) on Sep 23, 2004 at 10:08 UTC | |
|
Re: Perl2Exe converting my scripts to Japanese
by Anonymous Monk on Sep 17, 2004 at 03:53 UTC |