!/usr/bin/perl -w - for linux with debugging on use Shell qw(uname pwd); use Tk; use Expect; #use strict; require Tk::Dialog; require Tk::Radiobutton; $Expect::Exp_Internal=0; $Expect::Log_Stdout=1; my $sftpusr="muser"; my $sftppswd="mpswd"; my $timeout=5; my $location=""; my $lab; my @labName = (); @labSet = ( [ "", "", "", 0], [ "m5", "192.168.200.14", "41", 1], ); ####################################################################### $mw = MainWindow->new(-title => "LOGVIEW"); $ft = $mw->Frame->pack(-side => 'top', -fill => 'x'); $fb = $mw->Frame->pack(-side => 'bottom', -fill => 'x'); foreach (@labSet) { push( @labName, $_->[0]); } $ft->Label(-text => "Lab Name:")->pack(-side =>'left', -anchor => 'w' ); my $opt = $ft -> Optionmenu(-options =>\@labName, -command => \&displayLoads, -variable => \$location, -relief => 'sunken')->pack(-side =>'left', -anchor => 'w'); $fb->Button(-text => "Exit", -command => sub{exit;})->pack( -side => 'right'); $ft->Button(-text => "Display", -command => \&displayInfo )->pack( -side => 'right'); $t = $mw->Scrolled("Text")->pack(-side => 'left', -fill => 'x', -expand => 1); $ssh = new Expect; # forever loop MainLoop; ################################################################################################## sub displayLoads { foreach( @labSet) { if ( $_->[0] eq $location ) { $lab = $_; last; } } }sub displayInfo { tie *STDOUT, 'Tk::Text', $t; my $parms=sprintf("%s@%s", ${sftpusr}, $lab->[1]); print "**** pram $parms\n"; $ssh->spawn("ssh", $parms) or die "Cannot ssh to $lab->[1]\n"; $ssh->expect( $timeout, # ["Password Authentication"], ["Are you sure you want to continue connecting (yes/no)?", sub { my $self = shift; $self->send("yes\n"); exp_continue;} ], [".*password: ", sub { my $self = shift; $self->send("$sftppswd\n"); exp_continue; } ], [ 'timeout', sub { print "Error ssh login timeout\n"; exit} ], [".*-root>"], ); # check board type $ssh->send( "cat \/proc\/cpuinfo | grep platform | awk \'{print \$3}\'\n"); $ssh->expect( $timeout, ["XXXX", sub { my $self = shift; print "\n*** FAILED: Target board is not p$lab->[2] cpu **\n"; $self->soft_close(); exit(); } ], # [".*-root>"] , [ 'timeout', sub { print "Error ssh cmd cpuinfo timeout\n"; exit(); } ] ); }