![更改脚本函数中的 shell](https://linux22.com/image/175069/%E6%9B%B4%E6%94%B9%E8%84%9A%E6%9C%AC%E5%87%BD%E6%95%B0%E4%B8%AD%E7%9A%84%20shell.png)
我将 ZSH 作为我的主 shell,但在我的 中.zshrc
,我想使用 Expect 设置一个 ssh 命令,这样当我刷新构建时,我可以更轻松地 ssh 进入我的开发盒(实际上不需要安全性,所有这些都在 Intranet 上)各种各样的)。我可以ssh
用shell传递密码!#/usr/bin/expect
。
这样做符合犹太洁食吗?
password=sick_awesome_password6969
function expect_ssh () {
# I enter expect shell at the beginning of this function <==
#!/usr/bin/expect
set timeout 20
set cmd [lrange $argv 1 end]
set password [lindex $argv 0]
eval spawn $cmd
expect "password:"
send "$password\r";
interact
exit 0 # Then escape from it ? <==
}
default_boxssh_subnet=1
function bosh () {
if [[ ! $1 == *"."* ]];
then
# ssh [email protected].$default_boxssh_subnet.$1
expect_ssh 10.10.$default_boxssh_subnet.$1
else
# ssh [email protected].$1
expect_ssh 10.10.$default_boxssh_subnet.$1
fi
}
答案1
答案2
离开 choroba 的评论,我吸收了它并编写了一个帮助程序脚本以从我的调用.zshrc
(我还将密码放在一个文件中,因为我想,“好吧,我们已经在制作另一个文件了。”)
呃,我的点文件将会变得一团糟。
.zshrc
function expect_ssh () {
expect ~/.exp $2 ssh $1
}
. ~/.password_file.conf
default_boxssh_subnet=1
function bosh () {
if [ -z "$2" ];
then
func_password=$bosh_password
else
func_password=$2
fi
if [[ ! $1 == *"."* ]];
then
#ssh [email protected].$default_boxssh_subnet.$1
expect_ssh [email protected].$default_boxssh_subnet.$1 $func_password
else
#ssh [email protected].$1
expect_ssh [email protected].$default_boxssh_subnet.$1 $func_password
fi
}
.exp
#!/usr/bin/expect
set timeout 20
set cmd [lrange $argv 1 end]
set password [lindex $argv 0]
eval spawn $cmd
expect "password:"
send "$password\r";
interact