expect 批量监控主机】的更多相关文章

[oracle@OAPRIMARY shell]$ cat expect.sh while read line do user=`echo $line | awk '{print $1}'` ip=`echo $line |awk '{print $2}'` passwd=`echo $line | awk '{print $3}'` #把shell中的$user $ip $passwd参数传递给expect脚本 expect expect2.exp $user $ip $passwd done…
(1)expect实现ssh非交互登录 注意:注释不能出现这脚本里面 spawn表示开启一个会话 \r:表示回车,exp_continue :表示没有出现这样,继续往下执行 interact :停留在对面终端 #!/usr/bin/expect spawn ssh root@192.168.111.101 expect { "yes/no" { send "yes\r"; exp_continue } "password" { send &quo…
我们有时可能会批量去操作服务器,比如批量在服务器上上传某个文件,安装软件,执行某个命令和脚本,重启服务,重启服务器等,如果人工去一台台操作的话会特别繁琐,并浪费人力. 这时我们可以使用expect,向目标服务器上发送指令去实现批量操作. 下面的例子将在centos上将一个文件,批量拷贝到其他服务商上,并执行相应的命令 1. 在centos上安装expect yum install expect 2. 编写expect脚本 copyfilebatch.sh 下面的脚本将向内网IP为 192.168…
一个执着于技术的公众号 背景 修改Linux系统密码,执行passwd即可更改密码.可如果有成千上百台服务器呢,通过ssh的方式逐一进行修改,对我们来说,工作量是非常大,且效率非常低下.因此采用批量修改密码的方式是比较快的. 环境准备 需求:在Linux环境下运行,需要tcl和expect支持 检查系统是否有expect和tcl: 可以看到系统已经安装有这两个软件,如果没有,yum -y install expect tcl进行安装即可. 「实验说明:本文利用expect的自动化人机交互功能,登…
Expect安装 [root@web02 scripts]# yum install expect SSH密钥生成 [root@web02 scripts]# ssh-keygen -t dsa   <==生成密钥 Generating public/private dsa key pair. Enter file in which to save the key (/root/.ssh/id_dsa): Enter passphrase (empty for no passphrase): E…
sshkey.exp #!/usr/bin/expect# 由于是多台服务器,需要在shell脚本中循环调用该脚本 if { $argc != 2 } { send_user "usage: expect scp-expect.exp file host dir\n" exit } #定义变量set file [lindex $argv 0]set host [lindex $argv 1]set password "888888" #必须使用ssh-copy-id…
#!/bin/expect -- ########################################## zhichao.hu #Push the id.pas.pub public key to the target server through the SSH service to implement secret-free login. #Define an iplist Create an iplist file in the current directory. The…
#!/usr/bin/expect -f ########################################## hutu #Push the id.pas.pub public key to the target server through the SSH service to implement secret-free login. #Define an iplist Create an iplist file in the current directory. The co…
[root@node2 ssh]# cat auto_ssh.sh #!/usr/bin/expect -f ########################################## #通过SSH服务将id.pas.pub公钥推送到目标服务器实现免密登陆 #参数:1.system_username # 2.system_password # 3.system_hostname # 4.CommandList [多个命令间:间隔] #返回值: # 0 成功 # 1 参数个数不正确 #…
在跳板机上执行脚本,登录到远程机器分区格式化挂载命令 #!/bin/bashpasswd='engine'/usr/bin/expect <<-EOFset time 40spawn ssh root@172.18.3.114expect {"*yes/no" { send "yes\r"; exp_continue }"*password:" { send "$passwd\r" }}expect "*…