参考:
https://blog.csdn.net/lumping/article/details/108185246
https://blog.csdn.net/dblrxy417894/article/details/101590016
https://blog.csdn.net/kevin_luan/article/details/38147349
https://www.cnblogs.com/silentmuh/p/11907139.html
大概如下
sshpass -p 'password' ssh -o StrictHostKeyChecking=no root@$h-tt > /dev/null 2>&1 << remotessh
echo "i am in $h"
cd $dir
echo "$h" > tests
exit
remotessh
其中:
sshpass
要安装 ,yum -y install sshpass
-o StrictHostKeyChecking=no
是为了避免第一次登录出现公钥检查。
> /dev/null 2>&1
是不输出远程执行过程到本机
<< remotessh .... exit remotessh
中间的内容就是在远程执行的命令,remotessh可以替换成其他的词,重要的是这个形式
-tt
强制伪终端分配,即使标准输入不是终端