linux - 如何通过 SSH bash 脚本在远程服务器上进行 cd?

标签 linux bash unix ssh

我有一个 bash 脚本,用于通过 ssh 连接到远程服务器。那行得通,但是我希望脚本在连接后立即传递 cd/some/dir 的命令。这似乎不起作用。这是我的代码:

#!/bin/bash
echo "SSHing.."
ssh -i ~/.ssh/some-site.pem xxx@yyy.com
cd /some/dir        
read

如何在 SSH 连接建立后立即执行 cd 命令?

最佳答案

有两种简单的方法可以通过 SSH 从脚本内部执行命令:

1) ssh user@host 'command'

2)

ssh user@host <<<EOF
command1
command2
<...>
commandn
EOF

关于linux - 如何通过 SSH bash 脚本在远程服务器上进行 cd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14703262/

相关文章:

linux - 将查找结果复制到另一个目录时出现问题

c - setsockopt() 错误 : Numerical argument out of domain

python - 在 python 中访问之前的 bash 命令

c - 在 macOS 上编译 XDR 时出现问题(RPC types.h 问题)

c++ - 为什么 reinterpret_cast 不将 'unsigned char' 转换为 'char' ?

Python 3.5 setup.py egg_info 失败,错误代码为 1 [Linux]

node.js - express on alpine linux - 创建 express 应用程序失败

linux - Bash 参数的最大数量!= max num cp arguments?

linux - 删除特殊字符和批量重命名

c - Unix编程——信号处理器