# # # # # # 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/-side 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 -expand 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!', -borderwidth=>5, -width=>60, -command=>sub { &check_process; Win32::MsgBox("Operation has completed successfully, Please save your xls file - be aware of save path if you are using your admin account.", 0,$0); } )->pack(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 sysadmin\log\ApplicationSynchronizer'; open (LST, "$Data{source}") || &error_display($Data{source}); chomp (my @work_file=); 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') || Win32::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}, $info->{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 was found\n"; chomp(my @status = ); 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 detected.\n"; $Sheet1->Cells($row++, $col++)->{value}= 'No ApplicationSynchronizer 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;