Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Subject: [PATCH] Ktest: Added email support
- Ktest script will send emails when:
- 1: the script is started
- 2: the script is cancelled by Ctrl-C
- 3: the script failed with fatal errors
- 4: the script completes all testing
- Users have to setup the mailer provided in config prior to using this script.
- Supported mailers: mail, mailx, sendmail
- ---
- ktest.pl | 38 ++++++++++++++++++++++++++++++++++++++
- 1 file changed, 38 insertions(+)
- diff --git a/ktest.pl b/ktest.pl
- index 0c8b61f..ce38212 100755
- --- a/ktest.pl
- +++ b/ktest.pl
- @@ -22,6 +22,8 @@ my %evals;
- #default opts
- my %default = (
- + "USR_EMAIL" => "",
- + "MAILER" => "mailx", # default mailer
- "NUM_TESTS" => 1,
- "TEST_TYPE" => "build",
- "BUILD_TYPE" => "randconfig",
- @@ -204,6 +206,8 @@ my $install_time;
- my $reboot_time;
- my $test_time;
- +my $script_start_time = localtime();
- +
- # set when a test is something other that just building or install
- # which would require more options.
- my $buildonly = 1;
- @@ -1426,6 +1430,8 @@ sub dodie {
- print " See $opt{LOG_FILE} for more info.\n";
- }
- + send_email("KTEST: critical failure", "Your test on $script_start_time has failed.\n");
- +
- if ($monitor_cnt) {
- # restore terminal settings
- system("stty $stty_orig");
- @@ -4224,6 +4230,37 @@ sub set_test_option {
- return eval_option($name, $option, $i);
- }
- +sub _mailx_send {
- + my ($subject, $message) = @_;
- + system("$opt{MAILER} -s \'$subject\' $opt{USR_EMAIL} <<< \'$message\'");
- +}
- +
- +sub _sendmail_send {
- + my ($subject, $message) = @_;
- + system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $opt{USR_EMAIL}");
- +}
- +
- +sub send_email {
- + if ($opt{USR_EMAIL} ne "" &&
- + $opt{MAILER} ne "")
- + {
- + if ($opt{MAILER} eq "mail" || $opt{MAILER} eq "mailx"){ _mailx_send(@_);}
- + elsif ($opt{MAILER} eq "sendmail" ) { _sendmail_send(@_);}
- + else { doprint "\nYour mailer: $opt{MAILER} is not supported.\n" }
- + }
- + else
- + {
- + print "No email sent: email or mailer not specified in config."
- + }
- +}
- +
- +$SIG{INT} = sub {
- + send_email("KTEST: Your [$opt{TEST_TYPE}]test was cancelled", "Your test started on $script_start_time was cancelled: sig int");
- + die "\nCaught Sig Int, test interrupted: $!\n"
- +};
- +
- +send_email("KTEST: Your [$opt{TEST_TYPE}]test was started", "Your test was started on $script_start_time");
- +
- # First we need to do is the builds
- for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
- @@ -4429,5 +4466,6 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
- doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
- +send_email("KTEST: Your [$opt{TEST_TYPE}]test has finished!", "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
- exit 0;
- --
- 1.8.3.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement