添加系统脚本脚本
首先,我们写一个expect 脚本,放在
/usr/local/bin
目录下cd /usr/local/bin
创建expect 脚本文件
touch iterm2login.exp
vim iterm2login.exp
,编辑脚本内容,内容如下,#!/usr/bin/expect
set timeout 30
spawn ssh [lindex $argv 0]@[lindex $argv 1]
expect {
"(yes/no)?"
{send "yes\n";exp_continue}
"password:"
{send "[lindex $argv 2]\n"}
}
interact
wq 保存退出,然后还有最后一步。 给脚本添加读写权限,在当前目录执行
sudo chmod -R 777 iterm2login.exp
配置profile
command + o打开profile,配置Send text at start如下,
iterm2login.exp username ipAddress password
如:
iterm2login.exp root 192.168.1.1 test123
iterm2login.exp后面为三个参数