不好意思还忘了说那个脚本.
不好意思还忘了说那个脚本执行时间大概需要20分钟左右。
因为是在XP下先试运行,所有用的是MKS.
测试的内容: 公司的套装软件工作是否正常,全由bash 完成
用户提交页面 ---> 生成tmp env --> auto ftp remote server (Solaris, Linux & AIX) ---> auto telnet remote server ---> execute scripts ---> grep results log --> display within html
========================================================
tmp env
#!c:/perl/bin/perl.exe -w
require "cgi-lib.pl";
use CGI;
print "Content-type: text/html\n\n";
print "";
&getFormData;
$mytmpenv = $request{"tmpenv"};
$myusername = $request{"username"};
$mypassword = $request{"password"};
$mytestcasename = $request{"testcasename"};
$myplatform = $request{"platform"};
$myhostname = $request{"hostname"};
$myinstalltype = $request{"installtype"};
$myinstalllocation = $request{"installlocation"};
$mydr = $request{"dr"};
$myds = $request{"ds"};
$mydf = $request{"df"};
$myrtds = $request{"rtds"};
$myaseversion = $request{"asever"};
$myaselocation = $request{"aselocation"};
$myaseservername = $request{"aseservername"};
open(MYTMPENV,">>$mytmpenv") or die("Can't open environment log file.\n");
print MYTMPENV ("#!/usr/bin/bash\n");
print MYTMPENV ("# generate a tmp environment setting scripts\n");
print MYTMPENV ("user=$myusername\npasswd=$mypassword\ntestcase_name=$mytestcasename\nplatform=$myplatform\nhost=$myhostname\ninstall_type=$myinstalltype\ninstall_location=$myinstalllocation\nase_version=$myaseversion\nase_location=$myaselocation\naseservername=$myaseservername\n#=======================================\n. $myinstalllocation/SYBASE.sh\n");
print MYTMPENV ("mkdir $myinstalllocation/mylogs\n");
close(MYTMPENV);
if ( $mydr ne "")
{
open(MYTMPENV,">>$mytmpenv") or die("Can't open environment log file.\n");
print MYTMPENV ("#=======================================\n. runDR.sh\n#=======================================\n");
close(MYTMPENV);
}
if ( $mydf ne "")
{
open(MYTMPENV,">>$mytmpenv") or die("Can't open environment log file.\n");
print MYTMPENV ("#=======================================\n. runDF.sh\n#=======================================\n");
close(MYTMPENV);
}
if ( $myds ne "")
{
open(MYTMPENV,">>$mytmpenv") or die("Can't open environment log file.\n");
print MYTMPENV ("#=======================================\n. runDS.sh\n#=======================================\n");
close(MYTMPENV);
}
if ( $myrtds ne "")
{
open(MYTMPENV,">>$mytmpenv") or die("Can't open environment log file.\n");
print MYTMPENV ("#=======================================\n. runRTDS.sh\n#=======================================\n");
close(MYTMPENV);
}
open(MYTMPENV,">>$mytmpenv") or die("Can't open environment log file.\n");
print MYTMPENV ("\n");
print MYTMPENV ("mv $myinstalllocation/mylogs/results.log ~\n");
close(MYTMPENV);
# end code
sub getFormData
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$request{$name} = $value;
}
}
==================================================
auto telnet
#!c:/perl/bin/perl.exe -w
#
$myhost = $ARGV[0];
$myuser = $ARGV[1];
$mypasswd = $ARGV[2];
$mytestcase = $ARGV[3];
## Connect and login.
use Net::Telnet();
$mynet = new Net::Telnet (Prompt => '/[:#%>\$] $/', Timeout => 2000,
Errmode=>'die');
$mynet->open($myhost);
$mynet->login($myuser, $mypasswd);
@changeshell = $mynet ->cmd("bash");
@chmodscripts = $mynet ->cmd("chmod 775 runDF.sh runDS.sh runDR.sh runRTDS.sh ${myuser}_${mytestcase}_$myhost.sh");
@executesscripts = $mynet->cmd("${myuser}_${mytestcase}_$myhost.sh");
@clearscripts = $mynet ->cmd("rm -rf runDF.sh runDS.sh runDR.sh runRTDS.sh ${myuser}_${mytestcase}_$myhost.sh");
@getresults = $mynet->cmd("cat results.log");
print @getresults;
=====================================================
用户提交页面 调用程序
#!C:/Program Files/MKS Toolkit/mksnt/sh.exe
#
# autogen.sh
./autogenenv.pl
# change mode to execute this script
mv tmpenv.log tmpenv.sh
chmod 0755 tmpenv.sh
# pick up all parameters from form
#
user=`sed -n 's/^user=//p' tmpenv.sh`;export $user
passwd=`sed -n 's/^passwd=//p' tmpenv.sh`; export $passwd
platform=`sed -n 's/^platform=//p' tmpenv.sh`; export $platform
host=`sed -n 's/^host=//p' tmpenv.sh`;export $host
testcase=`sed -n 's/^testcase_name=//p' tmpenv.sh`; export $testcase;
# generate a temp file for different users
#
touch ${user}_${testcase}_$host.sh
cp tmpenv.sh ${user}_${testcase}_$host.sh
# create an auto ftp script file to server
#
echo "#!C:/Program Files/MKS Toolkit/mksnt/sh.exe" > myftp.sh
echo "#" >> myftp.sh
echo "port=21" >> myftp.sh
echo "mode='bin'" >>myftp.sh
echo "ftp -i -n <<!" >>myftp.sh
echo "open $host" >>myftp.sh
echo "user $user $passwd" >>myftp.sh
echo "$mode" >> myftp.sh
echo "mput run*.sh ${user}_${testcase}_$host.sh" >> myftp.sh
echo "bye" >> myftp.sh
echo "!" >>myftp.sh
./myftp.sh
# remove all temp files for safe reason
#
rm -rf ${user}_${testcase}_$host.sh tmpenv.sh myftp.sh
# create auto telnet to remote host, no matter which is Windows, Solaris or linux, ALL should work fine
#
cp autotelnet.pl $user.pl
# create results html based on the logs we get from target machine
#
# print header
#
NOW=`date`
echo ""
echo "<HTML>"
echo "<link rel="stylesheet" type= "text/css" href ="/cgi-bin/style.css" />"
echo "<HEAD><TITLE>Suite Automatic Test Results</TITLE></HEAD>"
echo ""
echo "<a name=TOP></a>"
echo "Last Updated: $NOW"
echo "<hr width='100%' size='3'>"
echo "<h3>Suite Automatic Test Results</h3>"
echo "<PRE>"
echo "Tester:" $user
echo "<PRE>"
echo "Platform:" $platform
echo "<PRE>"
echo "Testcase:" $testcase
echo "<PRE>"
echo "We are procceding your request now, please wait............"
echo "<hr width='100%' size='4'>"
./$user.pl $host $user $passwd $testcase $host << EOM
</BODY>
< /HTML>
EOM
# remove auto telnet files for username
#
rm -rf $user.pl