in reply to Re^4: Problem using Net::OpenSSH->capture to su to another user
in thread Problem using Net::OpenSSH->capture to su to another user

Show us how you do it from the command line.

Do you need to enter any password?

  • Comment on Re^5: Problem using Net::OpenSSH->capture to su to another user

Replies are listed 'Best First'.
Re^6: Problem using Net::OpenSSH->capture to su to another user
by Anonymous Monk on Jun 13, 2014 at 13:56 UTC
    From shell sudo -su nonroot (NOPASSWD) as nonroot user cd /directory; ./exec.sh parameter file.lst i tried to run the sudo -u nonrootuser 'cd /directory; ./exec.sh parameter file.lst' get command not found
      sudo doesn't accept shell expressions as commands. Just simple commands. You can invoque the shell explicitly though:
      sudo -u nonrootuser /bin/sh -c 'cd /directory; ./exec.sh'
        Please advise:
        my $BASE='/test'; @cmd='ls -lt '.$BASE.'/Logs/*.log'; my $ssh = Net::OpenSSH->new("$user:$pass\@$host", master_opts => [ +-o => "StrictHostKeyChecking=no" ]) or warn "Can't ssh to $host: " . +$ssh->error; if ($ssh->error) {print runlog "SSH connection to $host failed: " +. $ssh->error; die ; } my($stdout, $stderr)=$ssh->capture2({tty=>1},@cmd); #my($stdout, $stderr)=$ssh->capture2(@cmd); if ($stderr) {print "get logs failed $stderr\n";}else{print "$stdo +ut\n$exit";} $ssh = Net::OpenSSH->new("$user:$pass\@$host", master_opts => [-o +=> "StrictHostKeyChecking=no" ]) or warn "Can't ssh to $host: " . $ss +h->error; my($stdout, $stderr, $exit)=$ssh->scp_get({glob=>1},$BASE.'/Logs/* +.log','/var/tmp'); if ($stderr) {print "get logs failed $stderr\n";}else{print "$stdo +ut\n$exit"
        The first command ran ok but for the scp_get the log file get scp'ied, but I'm getting : Killed by signal 1. # set_error(1 - control command failed: master ssh connection broken)