我尝试使用以下 bash 脚本通过 ssh
和 pseudo-tty allocation
连接到远程服务器;
ssh -t -t user@remote-host
if [ -d "/test/dir_test" ]; then
sudo chown -R user:admin /test/dir_test/
sudo rm -rf /test/dir_test/*
else
sudo mkdir /test/dir_test/
fi
检查 /test/dir_test
是否存在于 remote-host
上,如果不存在则在 remote-host 上创建这样的目录 test/dir_test
;但是脚本不起作用,我想知道在这种情况下如何使用 ssh
和 pseudo-tty allocation
来做到这一点。
最佳答案
您必须像这样引用要发送到服务器的命令:
ssh -t -t user@remote-host "
if [ -d '/test/dir_test' ]; then
sudo chown -R user:admin /test/dir_test/
sudo rm -rf /test/dir_test/*
else
sudo mkdir /test/dir_test/
fi"
请注意,sudo
需要密码,除非在其配置中另有说明。
关于linux - if else in ssh pseudo-tty 分配给远程服务器怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58061148/