Very simple automation template
Published by Alphamonk on 2009/2/21 (958 reads)
I use this template to quickly automate a process that only I, will need to run. Typically someone will want me to preform an svn checkout and build base libraries and run certain simulations and send emails to them and their bosses about the pass and fail status of that run when I use a script as simple as this one. This script is only utilized when I am automating a process for a set amount or runs and I want to get the process up and running in less than an hour.
use strict; # This is a standard pragma I always use to keep variables local
use warnings; # Help with debugging
use Cwd; # current working directory
my $svninfo = "/path_to_svndir/bin/svn info";
my $svnco = "/path_to_svndir/bin/svn co";
# In case I dont want to checkout the entire repository
my $sw = "http://url_svn_repository/trunk/sw";
my $fw = "http://url_svn_repository/trunk/fw";
my $dir1 = "http://url_svn_repository/trunk/dir1";
my $dir2 = "http://url_svn_repository/trunk/dir2";
my $dir3 = "http://url_svn_repository/trunk/dir3";
my $blddir = "/home/alphamonk/build/test1";
my $mailto = "alphamonk@mydomain.com, jim@mydomain.com, jan@mydomain.com, joe@mydomain.com";
my $mailfrom = "buildguy@mydomain.com";
my ($command, @results, @cmdresult, @grepresults, @revinfo, $dir, $fwrevinfo,
$message,$subject,
);
$command = "$svninfo $sw";
@cmdresult = `$command`;
@grepresults = grep(/Revision/, @cmdresult);
@revinfo = split(/s+/, $grepresults[0]);
$swrevinfo = $revinfo[1];
$message = <<MESSAGE;
This is daily mail sent from Buildguy user to notify you of success or
failure of build script in $design
MESSAGE
chdir("$blddir") or die "Could not chdir to $blddir directoryn";
$dir = getcwd;
if ($dir eq "$blddir"){
mkdir("sw_rel_$revinfo") or die "Could not make firmware release directoryn";
chdir("sw_rel_$revinfo") or die "Could not chdir to sw_rel_$revinfon";
$command = "$svnco $fw";
system("$command") == 0 or notify("$fw checkout Failed",$message, $mailto, $mailfrom);
$command = "$svnco $sw";
system("$command") == 0 or notify("$sw checkout Failed",$message, $mailto, $mailfrom);
$command = "$svnco $dir1";
system("$command") == 0 or notify("$dir1 checkout Failed",$message, $mailto, $mailfrom);
$command = "$svnco $dir2";
system("$command") == 0 or notify("$dir2 checkout Failed",$message, $mailto, $mailfrom);
$command = "$svnco $dir3";
system("$command") == 0 or notify("$dir3 checkout Failed",$message, $mailto, $mailfrom);
chdir("$sw") or notify("Chdir to $sw Failed",$message, $mailto, $mailfrom);
$command ="./build.sh";
system("$command") == 0 or notify("Build Failed",$message, $mailto, $mailfrom);
chdir("$blddir/sw_rel_$revinfo") or notify("chdir to $dsn Failed",$message, $mailto, $mailfrom);
$command ="/path_to/commercial_simulation_software --arg1 --arg2 73";
system("$command") == 0 or notify("Make libraries Failed",$message, $mailto, $mailfrom);
$command = "./run";
system("$command") == 0 or notify("Dot Run Failed",$message, $mailto, $mailfrom);
$command = "/path_to/commercial_simulation_software --arg1 --arg2 104 --arg3 testbench2";
system("$command") == 0 or notify("make 104 failed",$message, $mailto, $mailfrom);
$command = "/path_to/commercial_simulation_software --arg1 --arg2 104 --arg3 testbench2 --arg4 --arg5 "special variables" ";
system("$command") == 0 or notify("Smoke Test Failed", $message, $mailto, $mailfrom);
notify("Build Success", $message, $mailto, $mailfrom);
} else {
print "$dir is not the proper directory to run this script inn";
}
sub notify{
($subject, $message, $mailto, $mailfrom) = @_;
if($mailto && $mailfrom && $subject && $message){
open(MAIL, "|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $mailton";
print MAIL "From: $mailfromn";
print MAIL "Subject: $subjectnn";
## Mail Body
print MAIL "$messagen";
} else {
print "Did not send mail messagen";
}
close(MAIL);
exit;
}
| Navigate through the articles | |
Perl Modules and My Functions that I use over and over again
|
What is a Infrastructure automation?
|
Voters total: 0
Average: 0
|
The comments are owned by the poster. We aren't responsible for their content.
|


