1#!/usr/bin/perl 2 3#Master control script; ltp_master 4# 3/12/02 William Jay Huie (creation) 5# 3/28/02 William Jay Huie minor updates 6#This will upload the ltprun script to the test system and kick off this script 7#uses the Net:Telnet and Net::Ftp modules from www.cpan.org 8#the ltprun script is a shell script to eliminate the need to write a script 9#to install these modules on all the target systems 10 11#FIXME: One problem is that the tests need to be run as root as as of now 12#this means that LTP_USER needs to be root, which means root needs to be 13#able to telnet and ftp into the machine. Couldn't figure out how to add 14#a su -c to the LTP_CMD_LINE variable, ssh will probably be the solution 15#but for now this works 16 17use Net::Telnet (); 18use Net::FTP (); 19 20#Leave this set to keep perl from buffering IO 21$| = 1; 22 23#CHANGEME: 24#change these for different defaults 25#Think carefully because things like ltprun.out are relied upon in the ltprun 26# script, so you need to change them there too, or better yet make them 27# cmd line parms 28#$LTP_USER = "ltp"; 29#$LTP_PASS = "ltp"; 30$LTP_USER = "root"; 31$LTP_PASS = "password"; 32$LTP_RUN = "ltprun"; 33#CHANGEME: 34#Can't use ~/bin so have to explicitly hardcode this directory 35$LTP_RUN_DIR = "/home/wjhuie/bin/"; 36$LTP_CMD_LINE = "chmod +x $LTP_RUN && nohup ./$LTP_RUN &> $LTP_RUN.out &"; 37 38#print "For this to work root must be able to ftp and telnet into the machines\n"; 39#print "Check #LTP_RUN_DIR/ltp_master for root password: $LTP_PASS\n"; 40 41#print "FIXME: Need to change this to su to root, not login over telnet\n"; 42#print " Or run in some other way like ssh\n"; 43 44if ( $ARGV[0] eq "-f" ) 45{ 46 if ( -f $ARGV[1] ) 47 { 48 open(FILE, $ARGV[1]) or die "Can't open $ARGV[1]"; 49 for ($i = 0; chomp($hosts[$i] = <FILE>); $i++) { ; } 50 $#hosts--; 51 close(FILE); 52 } 53 else { die "Please specify host list file with option -f\n"; } 54} 55elsif (@ARGV) 56{ @hosts = @ARGV; } 57else 58{ 59 print "HOSTS separate with [ENTER] finish with [^D]\n"; 60 chomp(@hosts = <STDIN>); 61} 62 63$t = new Net::Telnet (Timeout => 30, Prompt => '/.+[\$#] $/' 64# ,Dump_Log => "ltp_control.log" 65#Remove the # on the line above and a copy of the 66# data exchange will be saved to the file 'ms.log' 67 ); 68 69#FIXME: Need a better retry system, this would loop forever 70#$retry = 0; 71 72for ($j = 0; $j <= $#hosts; $j++) 73{ 74 chdir "$LTP_RUN_DIR" or die "Can't change to $LTP_RUN_DIR"; 75 print "\nAttempting to Upload $LTP_RUN to: $hosts[$j]"; 76 77 $ftp = Net::FTP->new($hosts[$j], Debug => 0) or 78 do { print "\n\tCouldn't connect to: $hosts[$j] --- skipping\n"; next; }; 79 $ftp->login($LTP_USER, $LTP_PASS) or die "\nUnable to login"; 80 $ftp->type('I') or die "\nUnable to set type to Binary"; 81 $ftp->put($LTP_RUN) or die "\nUnable to put $LTP_RUN"; 82 $ftp->quit; 83 print "\nUploading $LTP_RUN Done"; 84 85 print "\nConnecting to: $hosts[$j]"; 86 $t->open($hosts[$j]); 87 $t->errmode("return"); 88 $t->login($LTP_USER, $LTP_PASS) or 89 do { print "\n\tFailed Login to $hosts[$j]! "; next; 90#perhaps work in some sort of retry, but this way will loop forever 91# if ($retry) { $j--; } next; 92 }; 93 @l = $t->cmd("$LTP_CMD_LINE"); 94 95 if ($j == 0) 96 { 97 if ($l[0]) { print " >\n@l"; @base_output = @l; } 98 else { printf "\nReturned empty Buffer!\n"; } 99 } 100 $a = join("",@l); 101 $b = join("",@base_output); 102 if ($a ne $b) 103 { print "!>\n@l\n"; } 104 105 $t->buffer_empty(); 106 $t->close(); 107 print "\t Command Completed"; 108} 109print "\nAll Done!\n"; 110 111#Use snippit below in results script to convert timing info 112# from tar file name into human readable format 113#$foo = $ARGV[0]; 114#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($foo); 115#print "$foo\n"; 116#print "Hour: $hour Min: $min Sec: $sec\n"; 117 118