How to pass commands as arguments to ssh [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-02 14:16:10

I would say this:

sshpass -p XXXX ssh -oStrictHostKeyChecking=no wsuser@192.168.0.100 \
  "sudo docker exec -u postgres postgres-container \
  /bin/bash -c \"psql -d crawl-configuration -c 'select * from schema_version'\""

Double quote the whole command to be executed by ssh, then escape double quotes within the command.

Alternatively, use a here-doc:

sshpass -p XXXX ssh -T -oStrictHostKeyChecking=no wsuser@192.168.0.100 <<-'EOF'
    sudo docker exec -u postgres postgres-container \
    /bin/bash -c "psql -d crawl-configuration -c 'select * from schema_version'"
EOF

No quoting needed because of the quoted 'EOF' delimiter. The -T disables allocation of a pseudo-terminal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!