summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/shellcommands.pm
diff options
context:
space:
mode:
authorlevinse <levinse>2011-07-24 16:11:50 +0000
committerlevinse <levinse>2011-07-24 16:11:50 +0000
commit1b7e75938c52dd285ca95c56b56747c2ca001e3f (patch)
treeff119c5fafe1e7d12540988ce6785c587167ff3b /FS/FS/part_export/shellcommands.pm
parentdf839f170f0cafaeba41d3ed199bfbc1dfc1dc10 (diff)
shellcommands.pm: move to Net::OpenSSH and add ignored_errors option, RT831
Diffstat (limited to 'FS/FS/part_export/shellcommands.pm')
-rw-r--r--FS/FS/part_export/shellcommands.pm23
1 files changed, 21 insertions, 2 deletions
diff --git a/FS/FS/part_export/shellcommands.pm b/FS/FS/part_export/shellcommands.pm
index 50af45d..7343385 100644
--- a/FS/FS/part_export/shellcommands.pm
+++ b/FS/FS/part_export/shellcommands.pm
@@ -80,6 +80,9 @@ tie my %options, 'Tie::IxHash',
'Radius group mapping to reason (via template user)',
type => 'textarea',
},
+ 'ignored_errors' => { label => 'Regexes of errors to ignore, separated by newlines',
+ type => 'textarea'
+ },
# 'no_queue' => { label => 'Run command immediately',
# type => 'checkbox',
# },
@@ -350,6 +353,7 @@ sub _export_command {
host => $self->machine,
command => $command_string,
stdin_string => $stdin_string,
+ ignored_errors => $self->option('ignored_errors') || '',
);
if($self->option($action . '_no_queue')) {
@@ -440,6 +444,7 @@ sub _export_replace {
host => $self->machine,
command => $command_string,
stdin_string => $stdin_string,
+ ignored_errors => $self->option('ignored_errors') || '',
);
if($self->option('usermod_no_queue')) {
@@ -465,8 +470,22 @@ sub shellcommands_queue {
}
sub ssh_cmd { #subroutine, not method
- use Net::SSH '0.08';
- &Net::SSH::ssh_cmd( { @_ } );
+ use Net::OpenSSH;
+ my $opt = { @_ };
+ my $ssh = Net::OpenSSH->new($opt->{'user'}.'@'.$opt->{'host'});
+ die "Couldn't establish SSH connection: ". $ssh->error if $ssh->error;
+ my ($output, $errput) = $ssh->capture2($opt->{'command'});
+ die "Error running SSH command: ". $ssh->error if $ssh->error;
+ if ($errput && $opt->{'ignored_errors'} && length($opt->{'ignored_errors'})) {
+ my @ignored_errors = split('\n',$opt->{'ignored_errors'});
+ foreach my $ignored_error ( @ignored_errors ) {
+ $errput =~ s/$ignored_error//g;
+ }
+ chomp($errput);
+ }
+ die $errput if $errput;
+ die $output if $output;
+ '';
}
#sub shellcommands_insert { #subroutine, not method