-1

I am trying to issue command docker stop $(docker ps -a -q) over ssh, using Python's paramiko package

stdin,stdout,stderr = ssh_client.exec_command('docker stop $(docker ps -a -q)');
print stderr.readlines()

I get an error Illegal variable name. I tried putting in double quote (""), escape the $, (, ) ... but running out of ideas

pynexj
  • 19,215
  • 5
  • 38
  • 56
tallharish
  • 242
  • 1
  • 12

1 Answers1

4

Sounds like you're using as the login shell on the ssh server. Csh does not support $(...) so try

ssh_client.exec_command('docker stop `docker ps -a -q` ');

Csh example:

# echo $(echo foo)
Illegal variable name.
#
pynexj
  • 19,215
  • 5
  • 38
  • 56
  • Thanks. This is a university machine, so got the default shell to changed to bash. As expected, my original command runs fine as well :-) – tallharish Jun 01 '18 at 16:06