1、创建sh文件
vim xxx.sh
#!/usr/bin/expect
set PORT 22
set HOST ***.**.12.20
set USER root
set PASSWORD ************
spawn ssh -p $PORT $USER@$HOST
expect {
"yes/no"
{send "yes\r";exp_continue;}
"*password:*"
{ send "$PASSWORD\r" }
}
interact
2、给文件加上可执行权限:
chmod 777 xxx.sh
3、打开iterm2 -> preferences -> Profiles
4、点击下⾯“+”号,新建⼀个profile
5.Command 下面选择Command
6.在后面的输入框中输入:
expect /Users/xxx/xxx/xxx.sh
7.由于配置了expect导致rzsz命令不能用的解决方式
https://blog.51cto.com/fulin0532/2439271
https://www.sunjs.com/article/detail/7891c859e64b4ec6a40a5cb672ba6d43.html