source: other-projects/nightly-tasks/diffcol/trunk/task.pl@ 27657

Last change on this file since 27657 was 27657, checked in by ak19, 11 years ago

Delete the upload_dir and recreate it before moving the generated reports into here and uploading to puka. The diffcol cronjob will run on the main machine now, not the vm.

  • Property svn:executable set to *
File size: 21.9 KB
Line 
1#!/usr/bin/perl -w
2
3# This program is meant to run the nightly diffcol
4# It is meant to be an equivalent for the existing task bash script
5# But it is intended to be expanded to work for Windows and GS3
6# For windows, need to REMEMBER to set the correct shebangs at the top
7
8package diffcoltask;
9
10use Cwd;
11use Switch; # for switch(val) { case: ; ...}
12use File::Path; # for rmdir and mkdir type functions
13use File::Copy; # for recursive copying of folders but skipping .svn
14use File::Basename;
15
16use strict;
17no strict 'subs'; # allow barewords (eg STDERR) as function arguments
18
19my $isWin = ($^O =~ m/mswin/i) ? 1 : 0;
20my $sep = $isWin ? "\\" : "/";
21my $pathsep = $isWin ? ";" : ":";
22#my $script_ext = $isWin ? ".bat" : ".bash";
23my $setup_script = "setup"; # needs to become gs3-setup for GS3
24
25# TASK_HOME should be the toplevel diffcol folder
26$ENV{'TASK_HOME'} = getcwd unless defined $ENV{'TASK_HOME'};
27## print STDERR "@@@ TASK_HOME: ".$ENV{'TASK_HOME'}."\n";
28
29
30$ENV{'DATA_DIR'} = filename_concat($ENV{'TASK_HOME'}, "diffcol-data");
31$ENV{'UPLOAD_DIR'} = filename_concat($ENV{'TASK_HOME'}, "diffcol-reports");
32$ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign
33$ENV{'GSDL_SMTP'} = "";
34##print STDERR "@@@ email: ".$ENV{'MONITOR_EMAIL'}."\n";
35
36# control if an existing compiled greenstone is used
37# or, if one should be checked out, which revision to checkout from svn
38$ENV{'SVN_OPT_REV'} = "-r head";
39#$ENV{'GSDLHOME'}=
40#$ENV{'GSDL3SRCHOME'}=
41
42
43
44#parse arguments
45my $action = "all";
46if(scalar(@ARGV) > 1) {
47 &printusage();
48 exit 0;
49}
50
51if(scalar(@ARGV) == 0) {
52 $action="all";
53}
54else {
55 switch ($ARGV[0]) {
56 case qr/^(-h|-help|help)$/i { &printusage; exit 0; }
57 case qr/^(setup_greenstone|run_test|summarise|upload|all)$/ { $action=$ARGV[0]; }
58 else {
59 print STDERR "Bad subcommand.\n";
60 &printusage;
61 exit -1;
62 }
63 }
64}
65
66#check key environment vars are set
67if(!defined $ENV{'UPLOAD_DIR'}) {
68 print STDERR "Please set a UPLOAD_DIR for the test in an environment.sh file\n";
69 #return 1;
70}
71if(!defined $ENV{'DATA_DIR'}) {
72 print STDERR "Please set a DATA_DIR for the test in an environment.sh file\n";
73 #return 1;
74}
75if(!defined $ENV{'MONITOR_EMAIL'}) {
76 print STDERR "Please set a MONITOR_EMAIL for the test in an environment.sh file\n";
77 #return 1;
78}
79
80if($ENV{'DATA_DIR'} eq "/") {
81 print STDERR "DATA_DIR should not be the fs root\n";
82 #return 1;
83}
84
85print STDERR "DATA_DIR: ".$ENV{'DATA_DIR'}."\n";
86print STDERR "UPLOAD_DIR: ".$ENV{'UPLOAD_DIR'}."\n";
87
88#create an id for this test
89my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
90$year += 1900;
91$mon += 1;
92$mon = "0$mon" if ($mon < 10);
93$mday = "0$mday" if ($mday < 10);
94my $dateid="$year-$mon-$mday"; #my $dateid=($year+1900)."-".($mon+1)."-$mday";
95
96print STDERR "Starting test '$dateid'\n";
97
98
99# http://stackoverflow.com/questions/2149368/how-can-i-loop-through-files-in-a-directory-in-perl
100$ENV{'CLASSPATH'} = "";
101my $jar_lib_path = $ENV{'TASK_HOME'}.$sep."lib";
102my @files = <$jar_lib_path/*.jar>; # /full/path/to/diffcol/lib/*jar
103foreach my $file (@files) {
104 $ENV{'CLASSPATH'}=$file.$pathsep.$ENV{'CLASSPATH'};
105}
106##print STDERR "**** classpath: ".$ENV{'CLASSPATH'}."\n";
107
108
109#set the location of the full report
110my $xmlout=filename_concat($ENV{'DATA_DIR'}, "full-report-$dateid.xml");
111##print STDERR "XML: $xmlout\n";
112
113# the toplevel folder of the greenstone installation being used
114my $greenstone_home="";
115# gsdl is the checkout folder and can be greenstone2 or greenstone3
116my $gsdl="greenstone2";
117
118
119# Check if using existing compiled-up greenstone installation
120# and set the greenstone_home location accordingly
121
122if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
123 print STDERR "Found existing Greenstone home, will use that instead\n";
124 $greenstone_home=$ENV{'GSDLHOME'};
125} else {
126 $greenstone_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
127}
128##print STDERR "GSHOME: $greenstone_home\n";
129
130#do the requested action
131if($action eq "setup_greenstone") {
132 &setup_greenstone;
133}
134elsif ($action eq "run_test") {
135 &run_test;
136}
137elsif ($action eq "summarise") {
138 &summarise;
139}
140elsif ($action eq "upload") {
141 &upload;
142 &mail_with_report_attached;
143}
144elsif ($action eq "all") {
145 &setup_greenstone;
146 &run_test;
147 &summarise;
148 &upload;
149 &mail_with_report_attached;
150}
151
152##********************************
153
154sub printusage
155{
156 print STDERR "Run as: $0 (help|setup_greenstone|run_test|summarise|upload|all)\n";
157}
158
159
160#http://stackoverflow.com/questions/7427262/read-a-file-and-save-it-in-variable-using-shell-script
161
162sub setup_greenstone
163{
164 #clean up from previous tests
165 print STDERR "about to clean up any old tests (Ctrl-C to cancel)"; # no newline
166 for my $i ( 1..5 ) {
167 sleep 1; # 1 second
168 print STDERR ".";
169 }
170 print STDERR "\n";
171
172 # http://perldoc.perl.org/File/Path.html
173 print STDERR "cleaning up previous tests\n";
174 &File::Path::remove_tree($ENV{'DATA_DIR'});
175
176 print STDERR "creating the data dir\n";
177 &File::Path::make_path($ENV{'DATA_DIR'}); # works like mkdir -p
178
179 chdir($ENV{'DATA_DIR'});
180
181 # use existing compiled-up greenstone installation, if a GSDLHOME set
182 if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
183 print STDERR "Found existing Greenstone home, will use that instead";
184 return;
185 }
186
187 # Else checkout a GS from svn into DATA_DIR
188
189 #svn checkout of main gsdl directory
190 print STDERR "checkout $gsdl:\n";
191 my $cmd = "svn co ".$ENV{'SVN_OPT_REV'}." http://svn.greenstone.org/main/trunk/greenstone2 $gsdl";
192 ##print STDERR "Checkout CMD: $cmd\n";
193
194 # # unlike backticks operator, system() will print the output of the command to the screen as it executes
195 # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
196 my $status = system "$cmd"; #my $status = `$cmd`;
197 print STDERR "done\n";
198
199 ##print STDERR "$ENV{'DATA_DIR'}$sep$gsdl\n";
200
201 chdir("$ENV{'DATA_DIR'}$sep$gsdl");
202
203 ##print STDERR "@@@ OS: $^O.|".$Config{'archname64'}."|\n";
204
205 # if we're on linux/darwin, need gnome-lib for the correct architecture.
206 if(!$isWin) {
207
208 print STDERR "setting up gnome-lib-minimal for compilation\n";
209
210 # To get gnome-lib, need to determine bit architecture of the linux/darwin
211 # http://stackoverflow.com/questions/8963400/the-correct-way-to-read-a-data-file-into-an-array
212 # $Config{'archname64'} doesn't work on the Ubuntu and the Sys::Info package seems to not be supported
213 # well on ActivePerl.
214 # But since we know we're on a Linux/Darwin machine at this point, wecan just run `uname -m` and other linux cmds
215
216 my $gnome_lib_file = ($^O =~ m/macos/i) ? "darwin-intel" : "linux"; # assuming all darwin is intel, not ppc!!
217
218 my $bit_arch=`uname -m`;
219 $gnome_lib_file .= "-x64" if($bit_arch =~ m/64$/);
220
221 #svn checkout gnome-lib for this linux/darwin
222 chdir("$ENV{'DATA_DIR'}$sep$gsdl$sep"."ext"); #cd $DATA_DIR/$gsdl/ext
223
224 ##print STDERR "**** gnomelib: $gnome_lib_file\n";
225
226 # checkout and unpack gnome-lib-minimal
227
228 #svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-linux-x64.tar.gz gl.tar.gz
229 $cmd = "svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-".$gnome_lib_file.".tar.gz gl.tar.gz";
230 system $cmd;
231 system ("tar -xvzf gl.tar.gz");
232
233 chdir("gnome-lib-minimal");
234 ##print STDERR "*** ARCH: $bit_arch\n";
235
236 # need to run source devel.bash on gnome-lib followed by configure, make, make install
237 # in one go, in order to preserve the compile environment set up by sourcing devel.bash
238
239 # http://stackoverflow.com/questions/7369145/activating-a-virtualenv-using-a-shell-script-doesnt-seem-to-work
240 # http://ubuntuforums.org/showthread.php?t=1932504 linking /bin/sh to bash instead of dash
241
242# $cmd = "bash -c \"source ./devel.bash && cd ../.. && ./configure --enable-apache-httpd && make && make install\"";
243 $cmd = "bash -c \"";
244
245 $cmd .= "source ./devel.bash";
246 $cmd .= " && cd ../..";
247
248 #configure
249 # $cmd .= " && ./configure";
250 $cmd .= " && echo 'configure $gsdl: ' ";
251 $cmd .= " && echo '<configure>' >> $xmlout";
252 $cmd .= " && ./configure 2>> $ENV{'DATA_DIR'}/compilation-errors"; # configure
253 $cmd .= " && echo '</configure>' >> $xmlout";
254 $cmd .= " && echo 'done'";
255
256 #make
257 $cmd .= " && echo 'make $gsdl: '";
258 $cmd .= " && echo '<make>' >> $xmlout";
259 $cmd .= " && make 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make
260 $cmd .= " && echo '</make>' >> $xmlout";
261 $cmd .= " && echo 'done'";
262
263 #make install
264 $cmd .= " && echo 'make install $gsdl: '";
265 $cmd .= " && echo '<make-install>' >> $xmlout";
266 $cmd .= " && make install 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make install
267 $cmd .= " && echo '</make-install>' >> $xmlout";
268 $cmd .= " && echo 'done'";
269
270 $cmd .= "\""; # close off cmd to bash and run it
271 system $cmd;
272 }
273
274 # set the path to the greenstone_home variable
275 $greenstone_home="$ENV{'DATA_DIR'}$sep$gsdl";
276
277}
278
279# http://stackoverflow.com/questions/3377879/how-do-i-receive-command-output-immediately
280sub run_test
281{
282 open (my $xml_fh, '>'.$xmlout) || die "Could not open xml file $xmlout for appending: $!\n";
283
284 # perform the requested subcommands, outputting xml information
285 print $xml_fh "<test time=\"$dateid\" id=\"$dateid\">\n";
286
287 # make sure that diffcol/model-collect is up to date before copying it over to greenstone-home
288 print $xml_fh "Updating $ENV{'TASK_HOME'}/model-collect:\n";
289 my $cmd = "svn up $ENV{'TASK_HOME'}/model-collect"; #chdir("$ENV{'TASK_HOME'}/model-collect");
290 my $status = system "$cmd";
291
292 # go to whichever greenstone_home we're using
293 chdir($greenstone_home);
294
295 # get svn info
296 print STDERR "getting svn info: $xmlout\n";
297 print $xml_fh "<svn-info>\n";
298 run_and_print_cmd("svn info", $xml_fh);
299 print $xml_fh "</svn-info>\n";
300 print STDERR "done\n";
301
302 #make two copies of the model-collect directory in gsdl
303 #one to be rebuilt and one as the basis for comparison
304 #strip both of all .svn directories
305
306 #copy the model collections to the collect folder to be rebuilt
307 print STDERR "installing test collections and model collections to new $gsdl installation... ";
308
309 #clean up
310 if(-d "collect") {
311 &File::Path::remove_tree("collect") || die "Error could not delete collect: $!";
312 }
313 &File::Path::remove_tree("model-collect");
314
315 #copy to collect and strip .svn subfolders
316 &File::Path::make_path("collect"); # create the folder and copy contents across
317 &copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","model-collect"), "collect", ".svn");
318
319 #make the model copy
320 &File::Path::make_path("model-collect");
321 &copy_recursively("collect", "model-collect"); # copy contents across
322
323 print STDERR "done\n";
324
325
326 #for each collection, import, build and diff with its model counterpart
327 opendir my($collect_handle), "collect" or die "Could not open dir $greenstone_home/collect: $!";
328 for my $collection (readdir $collect_handle) {
329 next if ($collection eq "." || $collection eq "..");
330 ##next if ($collection ne "Small-HTML"); ## TEMPORARY, FOR TESTING THIS SCRIPT
331
332 #escape the filename (in case of space)
333 $collection =~ s@ @\\ @g;
334 #getting just the basename of the collection would have been necessary had we not cd-ed into $gsdl
335
336 print STDERR "*** Found collection $collection\n";
337 print $xml_fh "<collection-test name=\"$collection\">\n";
338
339 #import
340# Ensure the OIDtype for importing is hash_on_full_filename
341# "to make document identifiers more stable across upgrades of the software,
342# although it means that duplicate documents contained in the collection are
343# no longer detected automatically."
344 print STDERR "$collection - Importing:\n";
345 print $xml_fh "<import>\n";
346 &run_build_script("import.pl -OIDtype hash_on_full_filename $collection -removeold");
347 print $xml_fh "</import>\n";
348 print STDERR "done\n";
349
350 #build
351 print STDERR "$collection - Building:\n";
352 print $xml_fh "<build>\n";
353 &run_build_script("buildcol.pl $collection -removeold");
354 print $xml_fh "</build>\n";
355 print STDERR "done\n";
356
357 #rename the intermediate 'building' directory 'index'
358 print STDERR "$collection - Move \"building\" to \"index\"... ";
359 my $index = &filename_concat("collect", $collection, "index");
360 my $building = &filename_concat("collect", $collection, "building");
361 &File::Path::remove_tree($index);
362 # Renaming Directories, http://www.perlmonks.org/?node_id=177421
363 move($building, $index) or die "copy failed: $!"; # File::Copy::move
364 print STDERR "done\n";
365
366 #diffcol
367 print STDERR "$collection - Diffing:\n";
368 my $diffcol_dir = &filename_concat($ENV{'TASK_HOME'},"diffcol");
369 $cmd = "./diffcol.pl -output xml -verbosity 10 $collection";
370 &run_diff_script($cmd, $xml_fh, $diffcol_dir);
371
372 chdir($greenstone_home); # this is actually where we are
373 print STDERR "done\n";
374 print $xml_fh "</collection-test>\n";
375 }
376 closedir $collect_handle; # close handle to collect dir
377
378 print $xml_fh "</test>\n";
379 close($xml_fh);
380
381 print STDERR "done\n";
382}
383
384##***************************************************************
385# runs setup in greenstone_home before running the diff command
386sub run_diff_script {
387 my ($cmd, $fh, $diffcol_dir) = @_;
388
389 # we're in greenstone_home now
390 if(!$isWin) {
391 $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && cd $diffcol_dir && $cmd\"";
392
393 } else { # Need to prefix cmd -c/-k as necessary
394 $cmd = "cd $greenstone_home && set GSDLHOME=&& source $setup_script.bat && cd $diffcol_dir && $cmd";
395 }
396
397 return &run_and_print_cmd($cmd, $fh);
398}
399
400# runs setup in greenstone_home before running the given build command
401sub run_build_script {
402 my ($cmd, $fh) = @_;
403
404# chdir($greenstone_home);
405
406 # we are in $greenstone_home, can directly run the build cmd on the collection
407 if(!$isWin) {
408 $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && $cmd\"";
409
410 } else { # Need to prefix cmd -c/-k as necessary
411 $cmd = "set GSDLHOME=&& source $setup_script.bat && $cmd";
412 }
413
414 return system($cmd);
415 #return &run_and_print_cmd($cmd, $fh); # doesn't work on cmds chained with bash -c
416}
417
418
419# http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1activeperl%20sys::info
420# http://stackoverflow.com/questions/1477500/how-do-i-get-the-output-of-an-external-command-in-perl
421sub run_and_print_cmd {
422 my ($cmd, $fh) = @_;
423
424 open my $pin, "$cmd|" or die "unable to run cmd $cmd: $!"; # open(my $fh, '-|', 'powercfg -l') or die $!;
425
426 if(defined $fh) { # print cmd output both to the filehandle and to stdout
427 while (my $line = <$pin>) {
428 print $fh $line;
429# print STDOUT $line; # if also printing cmd output to STDOUT
430 }
431 }
432 else { # no filehandle, so just need to print to stdout
433
434 # unlike backticks operator, system() will print the output of the command to the screen as it executes
435 # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
436
437 my $status = system $cmd;
438 if($status != 0) {
439 print STDERR "ERROR ($status) running $cmd: $!\n";
440 }
441 }
442 close($pin);
443}
444
445sub filename_concat {
446 my $first_file = shift(@_);
447 my (@filenames) = @_;
448
449 # If first_file is not null or empty, then add it back into the list
450 if (defined $first_file && $first_file =~ /\S/)
451 {
452 unshift(@filenames, $first_file);
453 }
454
455 my $filename = join($sep, @filenames);
456 $filename =~ s/[\\\/]$//; # remove trailing slashes if any
457 return $filename;
458}
459
460
461# The following code is from
462# http://stackoverflow.com/questions/227613/how-can-i-copy-a-directory-recursively-and-filter-filenames-in-perl
463# It also states that "Perl's File::Copy is a bit broken (it doesn't copy permissions on Unix systems, for example)"
464sub copy_recursively {
465 my ($from_dir, $to_dir, $regex) = @_;
466 opendir my($dh), $from_dir or die "Could not open dir '$from_dir': $!";
467
468# if(-d !$to_dir) {
469# mkdir $to_dir or die "mkdir '$to_dir' failed: $!" if not -e $to_dir;
470# }
471
472 for my $entry (readdir $dh) {
473 next if ($entry eq "." || $entry eq "..");
474 next if (defined $regex && $entry =~ /$regex/);
475 my $source = "$from_dir/$entry";
476 my $destination = "$to_dir/$entry";
477 if (-d $source) {
478 mkdir $destination or die "mkdir '$destination' failed: $!" if not -e $destination;
479 copy_recursively($source, $destination, $regex);
480 } else {
481 copy($source, $destination) or die "copy failed: $!";
482 }
483 }
484 closedir $dh;
485 return;
486}
487
488sub summarise {
489
490 # make a summarised Xml report
491 print STDERR "Summarizing the xml report... ";
492 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/xml-report.xsl -OUT $ENV{'DATA_DIR'}/report-$dateid.xml";
493 my $status = system($cmd);
494 print STDERR "done\n";
495
496 # make a summarised HTMl report
497 print STDERR "Creating an html summary report... ";
498 $cmd = "java org.apache.xalan.xslt.Process -IN $ENV{'DATA_DIR'}/report-$dateid.xml -XSL $ENV{'TASK_HOME'}/xsl/html-report.xsl -OUT $ENV{'DATA_DIR'}/report-$dateid.html";
499 $status = system($cmd);
500 print STDERR "done\n";
501}
502
503sub upload {
504 # if the upload dir already existed, clear it of contents
505 if (-d $ENV{'UPLOAD_DIR'}) { #else rm $UPLOAD_DIR/*
506 # don't want to keep previous days reports
507 # else we will have to manually clear them at some point
508 # just generate the set of reports for this run of task.pl upload
509 # and
510 &File::Path::remove_tree($ENV{'UPLOAD_DIR'});
511 }
512 # recreate the upload directory
513 &File::Path::make_path($ENV{'UPLOAD_DIR'});
514
515 # copy all *.xml and *.html files across to UPLOAD_DIR
516 opendir my($dh), $ENV{'DATA_DIR'} or die "Could not open DATA_DIR: $!";
517 for my $entry (readdir $dh) {
518 next if ($entry !~ m/(\.xml|\.html)$/);
519 # get the absolute path to the files before copying them over
520 $entry = &filename_concat($ENV{'DATA_DIR'}, $entry);
521 copy($entry, $ENV{'UPLOAD_DIR'});
522 }
523 closedir $dh;
524
525
526 # Upload the html file to puka
527 #default identity dir
528 if ( ! exists $ENV{'IDENTITY_DIR'} ) {
529 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
530 }
531 if (! exists $ENV{'SNAPSHOT_MODE'} ) {
532 $ENV{'SNAPSHOT_MODE'} = "caveat";
533 }
534
535 #use the correct key for uploading
536 $ENV{'IDENTITY_FILE'} = "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
537 if(-f $ENV{'IDENTITY_FILE'}) {
538 # the report we want to upload is actually just report-$dateid.html
539 my $command = "cd \"$ENV{'UPLOAD_DIR'}\" && tar -c *.html | "; #&& cat *.html | "; # && tar -c * |
540 $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
541 $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
542 #print "$command\n";
543 my $status = system("$command");
544 if($status != 0) {
545 print STDERR "*** Failed to upload test report to nzdl\n";
546 }
547 } else {
548 print STDERR "*** Cannot upload the test report to nzdl from this machine\n";
549 }
550
551 print STDERR "Finished uploading\n";
552}
553
554# Sending emails with perl: http://learn.perl.org/examples/email.html
555# Sending email attachments with perl: http://www.perlmonks.org/?node_id=19430
556# Sadly none of the packages are installed by default and use of MIME::Lite is discouraged
557sub mail_with_report_attached
558{
559 # email out with report attached, if the tests failed
560 print STDERR "Checking if successful... \n";
561 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
562 #my $result = system($cmd);
563 my $result = `$cmd`;
564
565 print STDERR "result: $result\n";
566
567 if($result ne "yes") {
568 my $msg = "$gsdl regression test for $dateid failed";
569 my $subject = "Regression Test Failed"; #"$gsdl regression test for $dateid failed\n";
570 my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$dateid.html");
571
572 if($isWin) {
573 # http://stackoverflow.com/questions/709635/sending-mail-from-batch-file
574 #blat -to [email protected] -server smtp.example.com -f [email protected] -subject "subject" -body "body"
575
576 $cmd = "blat -to $ENV{'MONITOR_EMAIL'} -server $ENV{'GSDL_SMTP'} -f $attach_file -subject $subject -body $msg"; # need to install blat on windows
577
578 } else {
579 my $status = system("command -v mutt > /dev/null 2>&1;"); #better way of doing "which mutt"
580
581 if($status != 0) { # mutt doesn't exist, can't send attachments, so send simple email
582 $cmd="echo '$gsdl regression test for $dateid failed.' | mail -s 'Regression Test Failed' $ENV{'MONITOR_EMAIL'}";
583
584 print STDERR "********************************************\n";
585 print STDERR "No mutt installed, unable to mail attachment\n";
586 print STDERR "Inspect report at: $attach_file\n";
587 print STDERR "********************************************\n";
588 } else {
589 #$cmd = "bash -c \"echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}\"";
590 $cmd = "echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}";
591 }
592 }
593
594 # run the mail command
595 $result = system($cmd); #&run_and_print_cmd($cmd);
596 if($result != 0) {
597 print STDERR "*** Unable to send email: $?\n";
598 }
599 else {
600 print STDERR "Sent mail with report attached.\n";
601 }
602 } else {
603 print STDERR "********************************************\n";
604 print STDERR "Tests were successful. Not sending mail.\n";
605 print STDERR "********************************************\n";
606 }
607}
608
609# The old version of this program contained the following, consisting of 1 line of active code:
610
611 # Invoke as: sjmc@br:/research/sjm84/envi/bin$ ./envi diffcol summarise
612 # Doing so will call this pl file and pass in "summarise" in ARGV
613 # This pl file will in turn call the task executable in this folder
614 # passing in "summarise" as a parameter.
615#system("/bin/bash -c \"../etc/tasks/diffcol/task @ARGV\"");
616
617 ##system("/bin/bash -c \"./task @ARGV\"");
618 ##print STDERR "/bin/bash -c ../etc/tasks/diffcol/task @ARGV"
Note: See TracBrowser for help on using the repository browser.