23,121
社区成员
发帖
与我相关
我的任务
分享
#!/usr/bin/perl -w
use strict;
my $os = $^O;
mkdir "/mnt/prod_build" unless( -e -d "/mnt/prod_build");
my %download = &Read_ini;#
my $user = $download{"User_Mail"};
my $group = $download{"Language_Group"};
my $ver = $download{"Version"};
my $server_ip = $download{"Server_IP"};
my $server_user = $download{"Server_User"};
my $server_passwd = $download{"Server_Passwd"};
my $server_path = $download{"Server_Share"};
my $script_path = $download{"Script_Path"};
my @strings = split /\//, $server_path;
shift @strings;
my $server_share = shift @strings;
my $path = join "/", @strings;
my @mail_body;
if($os =~ /linux/i){
my $build_server = "//$server_ip/$server_share";
my $id_pwd = "username=$server_user,password=$server_passwd";
my $build_mount = "mount -t cifs -o $id_pwd $build_server /mnt/prod_build/";
push @mail_body, "Mount the build server on Linux to /mnt/prod_build!\n" unless system $build_mount;
} elsif($os =~ /aix/i){
my $mount_command = "mount -v cifs -n $server_ip/$server_user/$server_passwd /$server_share /mnt/prod_build";
push @mail_body, "Mount the build server on AIX to /mnt/prod_build!\n" unless system $mount_command;
}
my $copy_path = "/mnt/prod_build/$path/$ver";
if(-e -d $copy_path){
push @mail_body, "Your mount build server for copy build success!\n";
chomp(my $build_number = `cat $copy_path/currentbuild.txt`);
print "$build_number!\n";
mkdir "$script_path/slp/dlp" unless( -e -d "$script_path/slp/dlp");
mkdir "$script_path/slp/xlp" unless( -e -d "$script_path/slp/xlp");
if(-e -d "$copy_path/dlp/$group/$build_number"){
push @mail_body, "Find the dlp build-number folder to copy!\n";
unless(system "\\cp -rf $copy_path/dlp/$group/$build_number $script_path/slp/dlp"){
push @mail_body, "Copy dlp build!\n";
if(-e -d "$script_path/slp/dlp/$build_number"){
unless(system "chmod -R +x $script_path/slp/dlp/$build_number"){
push @mail_body, "Add dlp execute access!\n";
}
}
}
}else{
push @mail_body, "Could Not find the dlp build to copy, dlp download FAILED!\n";
}
if(-e -d "$copy_path/xlp/$group/$build_number"){
push @mail_body, "Find the xlp build-number folder to copy!\n";
unless(system "\\cp -rf $copy_path/xlp/$group/$build_number $script_path/slp/xlp"){
push @mail_body, "Copy xlp build!\n";
if(-e -d "$script_path/slp/xlp/$build_number"){
unless(system "chmod -R +x $script_path/slp/xlp/$build_number"){
push @mail_body, "Add xlp execute access!\n";
}
}
}
}else{
push @mail_body, "Could Not find the xlp build to copy, xlp download FAILED!\n";
}
}
else{
push @mail_body, "Your mount build server to copy build, MOUNT FAILED!\n";
}
my $mail = join '#', @mail_body;
print "start sent mail action!\n";
&SendMail($mail,$user);
#Read the download build config information
sub Read_ini{
my %download;
while(<>){
chomp;
next if /\A\s*\Z/ || /\A\s*#/;
if(/=/){
my($key,$value) = /^\s*(\w+)\s*=\s*(\S*)\s*$/;
$download{$key} = $value;
}
}
return %download;
}
#Send mail to owner after build download completed
sub SendMail{
my ($body,$user) = @_;
my $os = $^O;
# $user =~ s/@/\\@/g; #AIX will be failed if add and parse @
my $title = "Your build download completed on <<$os>>!";
if($os =~ /linux/){
open MAIL, '|-', "mail -s \"$title\" $user";
print MAIL $body;
close MAIL;
} elsif($os =~ /aix/) {
# open MAIL, '|-', "uuencode $body script.log | mail -s \"$title\" $user";
#above line, because open file handle MAIL to "print MAIL @$body" add mail body failed on aix
# system "echo @$body | mail -s \"$title\" $user";
#above line, because echo in shell, it can not use directly in perl.
system "mail -s \"$title\" $user <<EOF
Auto download SLP build completed. There are 4 actions as blow:
$body
Auto download SLP build done.
EOF";
# print MAIL $body;
# close MAIL;
}
}
#Download build information
#User_mail should be your Company internal mail ID, if you want add more than one person, please use one blank betwee them.
#Example: use1@.companycom sue2@company.com use3@company.com
User_Mail=use1@company.com
#Language_group is the language group such as: G1 G2 etc, there should be base one your file server folder info.
Language_Group=G1
#Version, base on your file server which you copy build from.
Version=5.02
#Server_IP, your file server wihch you copy from
Server_IP=192.168.10.10
#Server_Share, your build path, this path until the Version folder.
#Example my build server is: //192.168.10.10/Prod/DAILYBUILD/NL_BUILD/SLP/5.02/dlp(xlp)/build1_20140101.
#then I set the value of Server_Share is: /Prod/DAILYBUILD/NL_BUILD/SLP/
Server_Share=/Prod/DAILYBUILD/NL_BUILD/SLP/
#Server_user, the user you used to login on
Server_User=tester
#Server_passwd, the user passwod if your file server
Server_Passwd=password
#Script_Path, the full path where this script and properties file load
Script_Path=/home/Testing/502