20.27 分发系统介绍 expect脚本远程登录 脚本远程执行
2018-09-21 17:30
786 查看
20.27 分发系统介绍
shell项目-分发系统-expect
20.28 expect脚本远程登录
1. 安装expect :
[root@aminglinux-128 ~]# yum install -y expect 已加载插件:fastestmirror, langpacks Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.huaweicloud.com * updates: mirrors.163.com
自动远程登录
2. 创建配置1.expect脚本(远程登录) :
[root@aminglinux-128 ~]# vim 1.expect
添加内容(自动远程登录hao2机器,并执行命令):
#! /usr/bin/expect set host "192.168.193.127" set passwd "123456" spawn ssh root@$host expect { "yes/no" { send "yes\r"; exp_continue} "password:" { send "$passwd\r" } } interact
3. 增加1.expect脚本x权限 :
chmod a+x 1.expect
4. 执行1.expect脚本(远程登录) :
[root@aminglinux-128 ~]# ./1.expect spawn ssh root@192.168.193.127 The authenticity of host '192.168.193.127 (192.168.193.127)' can't be established. ECDSA key fingerprint is SHA256:uxHaWRc2lThYwxDrkf52bB9ATkoi/ar1cajntdh1vhI. ECDSA key fingerprint is MD5:f7:34:8c:d3:2d:c8:0f:99:69:d1:e3:7d:35:5f:8e:33. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.193.127' (ECDSA) to the list of known hosts. root@192.168.193.127's password: Permission denied, please try again. root@192.168.193.127's password: Last failed login: Fri Sep 21 17:05:12 CST 2018 from 192.168.193.128 on ssh:notty There was 1 failed login attempt since the last succe 5ac ssful login. Last login: Fri Sep 21 16:52:35 2018 from 192.168.193.1 [root@localhost ~]#
20.29 expect脚本远程执行命令
自动远程登录后,执行命令并退出
1. 远程hao2机器,创建/tmp/12.txt文件,追加重定向1212到/tmp/12.txt文件 :
[root@aminglinux-128 ~]# vim 2.expect
#!/usr/bin/expect set user "root" set passwd "123456" spawn ssh $user@192.168.193.127 expect { "yes/no" { send "yes\r"; exp_continue} "password:" { send "$passwd\r" } } expect "]*" send "touch /tmp/12.txt\r" expect "]*" send "echo 1212 > /tmp/12.txt\r" expect "]*" send "exit\r"
2. 增加2.expect脚本x权限 :
[root@aminglinux-128 ~]# chmod a+x 2.expect
传递参数
1.
vim 3.expect
#!/usr/bin/expect set user [lindex $argv 0] set host [lindex $argv 1] set passwd "admin" set cm [lindex $argv 2] spawn ssh $user@$host expect { "yes/no" { send "yes\r"} "password:" { send "$passwd\r" } } expect "]*" send "$cm\r" expect "]*" send "exit\r"
2. 增加3.expect脚本x权限 :
[root@aminglinux-128 ~]# chmod a+x 3.expect
3. 执行3.expect脚本 :
远程登录到指定用户名 主机ip 执行的多个命令(ls;w)
相关文章推荐
- 20.27 分发系统介绍 20.28 expect脚本远程登录 20.29 expect脚本远程执行
- 20.27 分发系统介绍 20.28 expect脚本远程登录 20.29 expect脚本远程执行
- 20.27 分发系统介绍 20.28 expect脚本远程登录 20.29 expect脚本远程执行
- 20.27分发系统介绍;20.28expect脚本远程登录;20.29expect脚本远程执行命令;20.30expect脚本传递参数
- 分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数
- 分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数
- 分发系统介绍,expect脚本远程登录,expect脚本远程执行命令,expect脚本传递参数
- 【shell编程】分发系统介绍、expect脚本远程登录、expect脚本远程执行命令和expect脚本传递参数
- 分发系统介绍 expect脚本远程登录 expect脚本远程执行命令 expect脚本传递参数
- 分发系统介绍,expect脚本远程登录,远程执行命令,传递参数
- 分发系统介绍expect脚本远程登录expect脚本远程执行命令 expect脚本传递参数
- 十七周三次课 2018.02.27分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数
- 分发系统介绍、expect脚本远程执行命令、expect脚本远程传递参数、expect脚本传递参数
- 十七周四次课(11月30日) 20.31 expect脚本同步文件 20.32 expect脚本指定host和要同步的文件 20.33 构建文件分发系统 20.34 批量远程执行命令
- expect脚本同步文件expect脚本指定host和要同步的文件 构建文件分发系统批量远程执行命令
- expect脚本同步文件、指定host和要同步的文件、构建文件分发系统、批量远程执行命令
- expect脚本同步文件、expect脚本指定host和要同步的文件、构建文件分发系统、批量远程执行
- 十七周四次课 2018.03.05 expect脚本同步文件、expect脚本指定host和要同步的文件、构建文件分发系统、批量远程执行命令
- expect脚本同步文件,expect脚本指定host和要同步的文件,构建文件分发系统,批量远程执行命令
- expect脚本同步文件,构建文件分发系统,批量远程执行命令