应用shell (ssh)远程链接主机

1.先用ssh root@192.168.88.132 连接主机,后退出。

2.然后运行脚本 rj.sh

/usr/bin/expect <<EOF
set timeout 30
spawn ssh -l root 192.168.88.132  "useradd lilei"
expect "password:"
send "123
:"
spawn ssh -l root 192.168.88.132 "yum install nmap -y"
expect "password:"
send "123
:"
expect eof
EOF
useradd lilei
~                                                                        
原文地址:https://www.cnblogs.com/MR-ws/p/11084746.html