Linux使用expect脚本实现远程机器自动登录 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    首先创建一个expect脚本ssh_expect,文件内容如下:

<code class="language-shell hljs bash">#!/usr/bin/expect -fset hostname [lindex $argv 0]set user [lindex $argv 1]set passwd [lindex $argv 2]set timeout 30set force_conservative 1if {$force_conservative} {    set send_slow {128 .1}}spawn ssh $user@$hostname;expect {        "*continue connecting (yes/no)?" { send -s "yes\r"; exp_continue }        "*assword:" {                send -s "$passwd\r";        }}interact</code>

    然后定义一些命令别名,比如:

<code class="language-shell hljs bash"><code class="language-shell hljs vbnet">alias   h101='ssh_expect 192.168.0.101<user><password>'alias   h102='ssh_expect 192.168.0.102<user><password>'</password></user></password></user></code></code>

    这些别名可以写到~/.bashrc文件中

    然后执行 h101 就可以自动登录192.168.0.101机器了,

Linux使用expect脚本实现远程机器自动登录

电脑资料

Linux使用expect脚本实现远程机器自动登录》(https://www.unjs.com)。

最新文章