expect

批量配置主机--expect

夙愿已清 提交于 2020-01-10 11:49:49
##安装expect yum -y install expect ###step1: 发送脚本文件到远程服务器; ###step2: 在远程服务器执行脚本;完成后删除脚本文件 #!/bin/bash IpList=`cat $1` for ip in $IpList do echo -e "\033[32m 'send script to $ip' \033[0m" /usr/bin/expect <<-EOF set timeout -1 set passwdlist { username {password1 password2 password3 ...} } foreach {u p} \$passwdlist { spawn scp script.sh \$u@$ip:/opt/ lassign \$p s(1) s(2) s(3) set i 1 expect { "*yes/no*" {send "yes\r";exp_continue} "*assword:*" {send "\$s(\$i)\r";incr i;set okpasswd [expr {\$i - 1}]; exp_continue} "*]*" { puts "scp completed"; exit} "Permission denied (publickey,gssapi-keyex

How to suppress expect send output?

和自甴很熟 提交于 2020-01-09 10:53:08
问题 I have an expect script which I'd like to behave as a fancy ssh program that hops several machines and sets up the environment on target machine before running the commands. I can use log_user 0/1 to turn off / on output from expect and that helps with password prompts and login banners, and commands to setup environment. But, like ssh, once my script starts to issue commands, I don't want to see the issued command. That is I don't want to see "command" after send "command\n". All I want to

How to suppress expect send output?

≡放荡痞女 提交于 2020-01-09 10:53:07
问题 I have an expect script which I'd like to behave as a fancy ssh program that hops several machines and sets up the environment on target machine before running the commands. I can use log_user 0/1 to turn off / on output from expect and that helps with password prompts and login banners, and commands to setup environment. But, like ssh, once my script starts to issue commands, I don't want to see the issued command. That is I don't want to see "command" after send "command\n". All I want to

1

时光怂恿深爱的人放手 提交于 2020-01-08 22:51:14
环境准备 准备两台Centos6服务器,1台Centos7服务器 系统: Centos6.8,Centos7.3 内存:1G cpu: 2核 IP地址: 10.0.0.22 10.0.0.23 10.0.0.41 # 安装ftp服务,在22上操作 yum -y install vsftpd # 启动ftp服务 service vsftpd start 访问测试页面 在23上操作 yum -y install lftp lftp 10.0.0.22 # 在22上操作 cd /var/ftp/ # 创建文件 touch 1.txt # 编辑文件 vim 1.txt # 随便输入点内容 hello ftp ! # 在23上操作 [ root@ localhost ~ ] # lftp 10.0.0.22 lftp 10.0.0.22:~ > ls -rw-r--r-- 1 0 0 11 Nov 21 04:32 1.txt drwxr-xr-x 2 0 0 4096 Mar 22 2017 pub # 切换文件至opt目录 lftp 10.0.0.22:/ > lcd /opt lcd ok, local cwd = /opt # 查看路径 lftp 10.0.0.22:/ > lpwd /opt lftp 10.0.0.22:/ > # 下载文件 get 1.txt # 退出当前环境

10非交互expect

喜你入骨 提交于 2020-01-08 09:49:24
非交互expect 介绍expect 认识expect expect是一个自动化交互套件,主要应用于执行命令和程序时,系统以交互形式要求输入指定字符串,实现交互通信。 expect自动交互流程 spawn启动指定进程---expect获取指定关键字---send向指定程序发送指定字符---执行完成退出. expect常用命令总结 spawn 交互程序开始后面跟命令或者指定程序 expect 获取匹配信息匹配成功则执行expect后面的程序动作 send exp_send 用于发送指定的字符串信息 exp_continue 在expect中多次匹配就需要用到 send_user 用来打印输出 相当于shell中的echo exit 退出expect脚本 eof expect执行结束 退出 set 定义变量 puts 输出变量 set timeout 设置超时时间 安装expect [root@hadoop04 ~]# yum -y install expect 编写expect脚本 初始版 [root@hadoop04 shell_expect]# vim expect_ssh01.sh #!/usr/bin/expect #开启一个会话 spawn ssh alice@172.22.34.19 expect { "yes/no" { send "yes\r";exp

shell ftp expect to intelligently copy files from local to ftp server

℡╲_俬逩灬. 提交于 2020-01-07 07:49:43
问题 I'm writing a shell script to automate the task of extracting data from a remote oracle database and temporarily storing it in the local machine in a folder say Csvfoder. I used 'expect' command to copy all files in this Csvfolder to the ftp server. These csv files in the Csvfolder have specific names( In the below example timestamp has two system timestamps joined) - For example, data extracted from oracle Table1 will have the name ABCD.(timestamp1).csv, after the script runs again after 15

expect: store output of a spawn command into variable

ぃ、小莉子 提交于 2020-01-07 03:53:06
问题 Inside my "expect" script: set $REPOS "/path/to/repo/" set $REV 73 set LOG [spawn svnlook log -r $REV $REPOS] What this will store in the variable "LOG": 16345 (memory location). What it should store in the variable "LOG": "some message of the svn commit log". It seems like the is a problem with executing a bash command and then storing that output into an expect variable. Have you got any ideas? I am new to expect and tcl. 回答1: You did't need spawn there. Try: set LOG [exec svnlook log -r

Updating IOS's via SCP in bash with expect

↘锁芯ラ 提交于 2020-01-07 03:41:26
问题 Good day. I am attempting to create/run a script that will allow me to send an updated IOS from a server to my network devices. The following code works when I put in a manual IP address right before the ":flash" command. #!/user/bin/expect set IOSroot "/xxxxx/xxx/c3750e-universalk9-mz.150-2.SE10a.bin" set pw xxxxxxxxxxxxxxxxxxx spawn scp $IOSroot 1.1.1.1:flash:/c3750e-universalk9-mz.150-2.SE10a.bin expect "TACACS Password:" send "$pw\r" interact The code there works great and as expected.

Using pexpect to automate a manage.py syncdb dialogue

时间秒杀一切 提交于 2020-01-07 02:11:57
问题 I am trying to use pexpect to automate this dialogue. Also below is the python program using pexpect. When I run the code...it waits for input at "Would you like to create one now? (yes/no):" then timesout with an error. It is expecting a yes or no. So...where did I err? The string matches the first input? ubuntu@ip-10-142-73-169:/opt/graphite/webapp/graphite$ sudo python manage.py syncdb Creating tables ... Creating table account_profile Creating table account_variable Creating table account

基本知识

北城余情 提交于 2020-01-07 00:51:55
0.jdk,jvm,jre jdk包括jre,jre=jvm+lib(类库)。运行Java时:去它的环境变量的path里面所列出的路径里面找到jre,然后运行java。因此安装了jdk后,要更改path,告诉电脑jre在这儿。 1.ssh 认证: ①基于口令的认证 只要知道对方的账号和口令就OK ②基于密钥的安全认证 说明:主机A首先(登录方)生成密钥对,包括公钥和私钥,并把公钥发给主机B。 2.小需求 注意:文件服务器上建立启动脚本(启动任务)和安装脚本(负责下载安装包并安装配置),启动脚本将安装脚本下发到各个节点中,然后各个节点执行安装脚本(服务器利用ssh命令一登录过去之后,执行安装脚本) scp: 将hello.sh放到另一台机器(hadoop0002上的当前目录下),以root登录。 用expect来自动登录到另一台机器上: 先安装expect: yum lis | grep expect yum -y install expect.x86_64 再vi a.sh: 说明:timeout超时设置为-1表示不等待了,执行完上一条直接到下一条了。如果设置为10,表示等待10s,10s之后认为是超时,则执行下一条命令。spawn监控。expect里面第一行,如果监控到有yes/no的字样,则进行后面的动作,发送yes\r,并继续监控。第二次如果有password。如果没了