nested ssh -t -t not providing $PS1

409 views Asked by At

I am trying to run a nested ssh -t -t but it won't provide me the environment variables when working with cat and echo.

#!/bin/bash

pass="password\n"
bla="cat <(echo -e '$pass') - | sudo -S su -"
ssh -t -t -t -t jumpserver "ssh -t -t -t -t server \"$bla\" "

I get an output without any variables taken into consideration. (e.g. PS1 does not get shown but commands work fine) The problem is related to cat <(echo -e '$pass') - but this was the way to keep echo alive after providing the password for sudo.

How can i achieve this and get environment variables to get a proper output?

Thanks.

1

There are 1 answers

3
Jakuje On
  1. The -tt is enough. Using more -t does not add any more effect and just makes an impression that you have no idea what are you doing.

  2. What is the point of cat <(echo -e) construction? Writing just echo would result in the same, isn't it?

  3. Why to use sudo su? sudo already does all you need, isn't it?

So how can it look in some fashionable manner?

pass="password\n"
bla="echo '$pass' | sudo -Si"
ssh -tt jumpserver "ssh -tt server \"$bla\""

And does it work? Try to debug the commands with -vvv switches to the ssh. It will show you what is actually executed and passed to each other shell.