Skip to main content
added 569 characters in body
Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k
ssh user@hostuser@server << EOF 
ssh user@hostuser@server sh << EOF 

Where sshd runs user-s-login-shell -c sh, so you know a Bourne-like shell is interpreting your code.

As an example that JVM_ARGS="-Xms512m -Xmx25000m" ./jmeter.sh... is Bourne-shell or compatible syntax. It would work in csh, tcsh, rc, es, fish shells, so wouldn't work with ssh user@server sh << EOF if the login shell of user on server was one of those shells.

A significant difference though is that in that case, user-s-login-shell is not started as a login shell so won't read /etc/profile or ~/.profile (or the equivalent for the user's login shell) to set the login session up.

Alternatively, you could convert that code to a syntax compatible to all those shells: env JVM_ARGS='-Xms512m -Xmx25000m' ./jmeter.sh... (use single quotes instead of double quotes and use env to pass an env var instead of the Bourne/rc specific envvar=value cmd syntax).

ssh user@host << EOF 
ssh user@host sh << EOF 

Where sshd runs user-s-login-shell -c sh, so you know a Bourne-like shell is interpreting your code.

A significant difference though is that in that case, user-s-login-shell is not started as a login shell so won't read /etc/profile or ~/.profile (or the equivalent for the user's login shell) to set the login session up.

ssh user@server << EOF 
ssh user@server sh << EOF 

Where sshd runs user-s-login-shell -c sh, so you know a Bourne-like shell is interpreting your code.

As an example that JVM_ARGS="-Xms512m -Xmx25000m" ./jmeter.sh... is Bourne-shell or compatible syntax. It would work in csh, tcsh, rc, es, fish shells, so wouldn't work with ssh user@server sh << EOF if the login shell of user on server was one of those shells.

A significant difference though is that in that case, user-s-login-shell is not started as a login shell so won't read /etc/profile or ~/.profile (or the equivalent for the user's login shell) to set the login session up.

Alternatively, you could convert that code to a syntax compatible to all those shells: env JVM_ARGS='-Xms512m -Xmx25000m' ./jmeter.sh... (use single quotes instead of double quotes and use env to pass an env var instead of the Bourne/rc specific envvar=value cmd syntax).

added 9 characters in body
Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

Even if you used: ssh ... << 'EOF' so as to avoid variablesparameter expansion, command substitutionssubstitution and arithmetic expansion being performed inside the here-document, ssh would be fed:

Even if you used: ssh ... << 'EOF' so as to avoid variables, command substitutions and arithmetic expansion being performed inside the here-document, ssh would be fed:

Even if you used: ssh ... << 'EOF' so as to avoid parameter expansion, command substitution and arithmetic expansion being performed inside the here-document, ssh would be fed:

added 924 characters in body
Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

The backslashes can be avoided by using xargs:

ssh user@server sh << EOF command_one xargs command_two << END_OF_ARGS argument1 argument2 argument3 argument4 argument5 argument6 argument7 END_OF_ARGS command_three EOF 

Or by using a shell like rc, ksh93, zsh, bash, yash and an array:

With rc/zsh syntax:

ssh user@server zsh << 'EOF' command_one args=( argument1 argument2 argument3 argument4 argument5 argument6 argument7 ) command_two $args command_three EOF 

(here quoting EOF so that $args is not expanded by the local shell).

Or with the ksh93/bash/yash syntax (also works with zsh):

ssh user@server bash << 'EOF' command_one args=( argument1 argument2 argument3 argument4 argument5 argument6 argument7 ) command_two "${args[@]}" command_three EOF 

The backslashes can be avoided by using xargs:

ssh user@server sh << EOF command_one xargs command_two << END_OF_ARGS argument1 argument2 argument3 argument4 argument5 argument6 argument7 END_OF_ARGS command_three EOF 

Or by using a shell like rc, ksh93, zsh, bash, yash and an array:

With rc/zsh syntax:

ssh user@server zsh << 'EOF' command_one args=( argument1 argument2 argument3 argument4 argument5 argument6 argument7 ) command_two $args command_three EOF 

(here quoting EOF so that $args is not expanded by the local shell).

Or with the ksh93/bash/yash syntax (also works with zsh):

ssh user@server bash << 'EOF' command_one args=( argument1 argument2 argument3 argument4 argument5 argument6 argument7 ) command_two "${args[@]}" command_three EOF 
Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k
Loading