0

I write a script who should login to a server via ssh and do something there. So I write two parts. First part:

myLoginPassword="loginpassword"
sshpass -p $myLoginPassword ssh -t user@machine

Works fine. Second part:

mySudoPassword="sudopassword"
/bin/bash -c "su -c - myadminuser <<< $mySudoPassword whoami"

If I run the first part and then run the second part on the target machine, it works fine.

Now, I want to join this two parts into one:

sshpass -p $myLoginPassword ssh -t user@machine /bin/bash -c "su -c - myadminuser <<< $mySudoPassword whoami"

But now, I get the error message:

sh: 1: Syntax error: redirection unexpected

The origin of the error is, that the Bourne Shell can not handle the here-string. But why is it now a Bourne Shell and not the bash, if I write /bin/bash -c to use the bash?

0 Answers0