Linux登录远程机脚本,Linux中使用expect脚本实现远程机器自动登录
发布日期:2021-06-27 04:24:43 浏览次数:12 分类:技术文章

本文共 529 字,大约阅读时间需要 1 分钟。

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

#!/usr/bin/expect -f

set hostname [lindex $argv 0]

set user [lindex $argv 1]

set passwd [lindex $argv 2]

set timeout 30

set force_conservative 1

if {$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

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

alias h101='ssh_expect 192.168.0.101 '

alias h102='ssh_expect 192.168.0.102 '

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

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

转载地址:https://blog.csdn.net/weixin_42166105/article/details/116696810 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:linux查看修改环境变量日志,Linux环境变量的设置和查看方法
下一篇:linux进程间传值,Linux 下进程间通信机制(六) 信号灯集 Semaphore Arrays

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月20日 03时35分51秒