From 43613383b248e4c6d8ccfdac98ec114f127290d7 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 17 Mar 2016 16:45:23 +0100 Subject: (re)added binmode(utf8) added special return code wich means success with errors diff --git a/rhautoimport b/rhautoimport index 1ffd50f..4901dc2 100755 --- a/rhautoimport +++ b/rhautoimport @@ -69,6 +69,9 @@ fi 0) bsd-mailx -a "Content-Type: text/plain; charset=utf-8" -s "$TITLE - Imported Successfully" $MAIL_TO < $LOG_FILE ;; + 23) + bsd-mailx -a "Content-Type: text/plain; charset=utf-8" -s "$TITLE - Imported Successfully (partially failed - check log!)" $MAIL_TO < $LOG_FILE + ;; 42) # do nothing - the script didn't import anything but no message should be sent ;; diff --git a/rhautoimport-btl b/rhautoimport-btl index cbeb8bf..a70ec83 100755 --- a/rhautoimport-btl +++ b/rhautoimport-btl @@ -40,6 +40,10 @@ my $RD_GROUP = "betweenlin"; my $PV_ID = '221'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + my $curweek = RHRD::utils::get_rd_week(); if($curweek == 2 || $curweek == 4) { print "please don't run this script in week 2 or 4!\n"; @@ -142,11 +146,17 @@ if($ret) { print "\nImport Success:\n\n"; print $log; print "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +my $exit_code = 0; +($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +print $log; +if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; +} unlink($STAT_FILE); open(my $fhs, '>', $STAT_FILE); print $fhs "$file"; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport-dn b/rhautoimport-dn index 62ba332..c9ff637 100755 --- a/rhautoimport-dn +++ b/rhautoimport-dn @@ -40,6 +40,10 @@ my $RD_GROUP = "democracyn"; my $PV_ID = '111'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + if($#ARGV >= 0 && $ARGV[0] eq 'last') { print "!!!This is the last attempt, there won't be a retry on error!!!\n"; $LAST_RUN = 1; @@ -154,6 +158,7 @@ for my $entry ($headlines_feed->entries) { print "\n\nwill import '$uri' to show $show_id, $show_title\n\n"; +my $exit_code = 0; my ($ret, $log) = rhautoimport::import_uri($show_id, $uri->as_string); if($ret) { print "\nImport Error:\n\n"; @@ -165,7 +170,15 @@ print "\nImport Success:\n\n"; print $log; if($sum_title ne "") { print "\n"; - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_day), "1", 0); + ($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_day), "1", 0); + print $log; + if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; + } +} else { + print "\nIgnoring missing note - manual intervention necessary!\n"; + $exit_code = 23; } unlink($STAT_FILE); @@ -173,4 +186,4 @@ open(my $fhs, '>', $STAT_FILE); print $fhs $file; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport-nw b/rhautoimport-nw index d2168f2..302b572 100755 --- a/rhautoimport-nw +++ b/rhautoimport-nw @@ -40,6 +40,10 @@ my $RD_GROUP = "netwatcher"; my $PV_ID = '73'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + if($#ARGV >= 0 && $ARGV[0] eq 'last') { print "!!!This is the last attempt, there won't be a retry on error!!!\n"; $LAST_RUN = 1; @@ -150,11 +154,17 @@ if($ret) { print "\nImport Success:\n\n"; print $log; print "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +my $exit_code = 0; +($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +print $log; +if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; +} unlink($STAT_FILE); open(my $fhs, '>', $STAT_FILE); print $fhs "$file"; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport-oi b/rhautoimport-oi index 987a700..71039f6 100755 --- a/rhautoimport-oi +++ b/rhautoimport-oi @@ -41,6 +41,10 @@ my $RD_GROUP = "ondainfo"; my $PV_ID = '220'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + my $curweek = RHRD::utils::get_rd_week(); if($curweek == 1 || $curweek == 3) { print "please don't run this script in week 1 or 3!\n"; @@ -143,7 +147,13 @@ if($ret) { print "\nImport Success:\n\n"; print $log; print "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +my $exit_code = 0; +($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +print $log; +if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; +} unlink($STAT_FILE); open(my $fhs, '>', $STAT_FILE); @@ -155,4 +165,4 @@ open($fhs, '>', $LAST_FILE); print $fhs "$broadcast_num"; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport-ra b/rhautoimport-ra index ff95bcc..3570dab 100755 --- a/rhautoimport-ra +++ b/rhautoimport-ra @@ -40,6 +40,10 @@ my $RD_GROUP = "RadioATTAC"; my $PV_ID = '76'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + if($#ARGV >= 0 && $ARGV[0] eq 'last') { print "!!!This is the last attempt, there won't be a retry on error!!!\n"; $LAST_RUN = 1; @@ -141,13 +145,20 @@ if($uri eq "") { exit 1; } +my $exit_code = 0; print "\n\nwill import '$uri' to show $show_id, $show_title\n"; my ($ret, $log, $keptfile_uri) = rhautoimport::import_uri($show_id, $uri->as_string, "keep"); if($ret == 0) { print "\nImport Success:\n\n"; print $log; print "\n"; - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date), "1"); + ($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date), "1"); + print $log; + if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; + } + print "\n"; if(!defined($keptfile_uri)) { @@ -162,12 +173,19 @@ if($ret == 0) { print "\nImport Success:\n\n"; print $log; print "\n"; - rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date_reb), "2"); + ($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, sprintf("%04d-%02d-%02d", @import_date_reb), "2"); + print $log; + if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; + } + } else { print "\nImport Error:\n\n"; print $log; print "\n\nNot adding PV note!!"; print "\n\nSince the import for the regular broadcast went through we will not retry this import!!!"; + $exit_code = 23; } } else { print "\nImport Error:\n\n"; @@ -181,4 +199,4 @@ open(my $fhs, '>', $STAT_FILE); print $fhs "$file"; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport-rs b/rhautoimport-rs index 8143977..d106692 100755 --- a/rhautoimport-rs +++ b/rhautoimport-rs @@ -41,6 +41,10 @@ my $RD_GROUP = "radioStimm"; my $PV_ID = '75'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + my $curweek = RHRD::utils::get_rd_week(); my %week_table = ( 1 => 2, 2 => 6, 3 => 2, 4 => 6 ); my $nextweek = $curweek == 4 ? 1 : $curweek + 1; @@ -196,11 +200,17 @@ if($ret) { print "\nImport Success:\n\n"; print $log; print "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +my $exit_code = 0; +($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +print $log; +if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; +} unlink($STAT_FILE); open(my $fhs, '>', $STAT_FILE); print $fhs "$id\n$file"; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport-tr b/rhautoimport-tr index 8f38839..21b3a0a 100755 --- a/rhautoimport-tr +++ b/rhautoimport-tr @@ -40,6 +40,10 @@ my $RD_GROUP = "tierrecht"; my $PV_ID = '506'; my $LAST_RUN = 0; +binmode(STDIN, ":utf8"); +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + my @today = Date::Calc::Standard_to_Business(Date::Calc::Today()); if($today[2] == 5) { print "please don't run this script on fridays!\n"; @@ -150,11 +154,17 @@ if($ret) { print "\nImport Success:\n\n"; print $log; print "\n"; -rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +my $exit_code = 0; +($ret, $log) = rhautoimport::pv_add_note($sum_title, $sum_text, $PV_ID, $id, "1"); +print $log; +if($ret) { + print "\nIgnoring failed note import - manual intervention necessary!\n"; + $exit_code = 23; +} unlink($STAT_FILE); open(my $fhs, '>', $STAT_FILE); print $fhs "$file"; close($fhs); -exit 0; +exit $exit_code; diff --git a/rhautoimport.pm b/rhautoimport.pm index 97d6429..f2e24cc 100644 --- a/rhautoimport.pm +++ b/rhautoimport.pm @@ -212,13 +212,15 @@ sub pv_add_note my $err_out = join('', <$error>); my $read_out = join('', <$reader>); if ( $? >> 8 ) { - print "\n\nPV: adding note returned non-zero value\n"; - print "STDERR:\n" . $err_out . "\n" unless $err_out eq ''; - print "STDOUT:\n" . $read_out . "\n" unless $read_out eq ''; - print "Ignoring failed headline import!\n"; + my $log = "\n\nPV: adding note returned non-zero value\n"; + $log .= "STDERR:\n" . $err_out . "\n" unless $err_out eq ''; + $log .= "STDOUT:\n" . $read_out . "\n" unless $read_out eq ''; + return(1, $log); } else { - print $read_out . "\n" unless $read_out eq ''; - print $err_out . "\n" unless $err_out eq ''; + my $log = ''; + $log .= $read_out . "\n" unless $read_out eq ''; + $log .= $err_out . "\n" unless $err_out eq ''; + return(0, $log); } } -- cgit v0.10.2