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

Similar question hope I can tag along with this thread. Need to run sudo -su nonroot and get a shell then run "cd /directory" and run a script with parameters in the directory like "./exec.sh parm1 file.lst" tried with
@cmd = "cd /directory; ./exec.sh parm1 file.lst"; $ssh->capture2({tty=>1},'sudo', '-su', "$nonrootuser", '--', @cmd)
The echo commands in script listed but no actual executes? Any advice?

Replies are listed 'Best First'.
Re^5: Problem using Net::OpenSSH->capture to su to another user
by salva (Canon) on Jun 13, 2014 at 12:34 UTC
    Show us how you do it from the command line.

    Do you need to enter any password?

      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'