bash 如何通过 ssh 检查目录是否存在并将结果返回到主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15927911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check if dir exists over ssh and return results to host machine
提问by hax0r_n_code
I'm trying to establish an SSH connection and see if a directory exist, and if that directory exists I want to run commands on the local machine that made the SSH call.
我正在尝试建立 SSH 连接并查看目录是否存在,如果该目录存在,我想在进行 SSH 调用的本地计算机上运行命令。
Here is what I've attempted:
这是我尝试过的:
if [ ssh -t username@ssh_server -d /directory ]
then
{
commands....
}
fi
Is something like this possible?
这样的事情可能吗?
回答by anishsane
You are very close:
你非常接近:
Change if statement to
将 if 语句更改为
if ssh username@ssh_server '[ -d /directory ]'
I am assuming that you have setup key-based authentication.
我假设您已经设置了基于密钥的身份验证。