linux-01 sbin]# mkdir expect [root@linux-01 sbin]# cd expect/ [root@linux-01 expect]# vim load.expect.../usr/bin/expect set user [lindex $argv 0] set host [lindex $argv 1] set passwd "123qwe" set cm [lindex.../usr/bin/expect set passwd "123qwe" set host [lindex $argv 0] set file [lindex $argv 1] spawn rsync -.../usr/bin/expect set passwd "123qwe" set host [lindex $argv 0] set file [lindex $argv 1] spawn rsync -.../usr/bin/expect set host [lindex $argv 0] set passwd "123qwe" set cm [lindex $argv 1] spawn ssh root@
@(Linux 命令脚本) 功能类似 xshell 这类终端管理工具,将需要登录的机器ip信息统一记录在一个host文件中,登录直接选择对应序号就好,减少重复输入ip,账号。...host.list) echo "SSH : " $ip expect ssh.exp $ip $name $passwd $port 自动填写 ssh 密码脚本 set timeout 1200 set ip [lindex...$argv 0] set name [lindex $argv 1] set passwd [lindex $argv 2] set port [lindex $argv 3] spawn ssh...ssh -p 22 -l lcd 192.168.37.129 lcd@192.168.37.129's password: Welcome to Ubuntu 16.04.2 LTS (GNU/Linux
/usr/bin/expect -f set ip [lindex $argv 0 ] set username [lindex $argv 1 ] set password [lindex...$argv 2 ] set superpassword [lindex $argv 3 ] set timeout 10 spawn telnet $ip expect...以上这篇linux expect 自动登录交换机保存配置的方法就是小编分享给大家的全部内容了,希望能给大家一个参考。
/usr/bin/expect set dbip_addr [lindex $argv 0] set dbip_port [lindex $argv 1] set ip_addr [lindex $...而且会进行基本的校验,linux环境下没有问题,暂时排除了Unix的设置。 #####Solaris的vi问题 至于solaris的防火墙设置,会和linux有差别,举一个例子。...root@xxxxx # vi /etc/ipf/ipf.conf linux: Unknown terminal type I don't know what kind of terminal you...are on - all I have is 'linux'....ipf.conf" 933 lines, 62110 characters block in log on e1000g0 from any to any # echo $TERM linux
export export LSCOLORS=gxfxcxdxbxegedabagacad #sets up theprompt color (currently a green similar to linux.../usr/bin/expect set timeout 30 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] expect...{send "yes\n";exp_continue} "password:" {send "[lindex $argv 3]\n"} } interact 如上面的代码所示...,其含有四个参数,分别为 [lindex $argv 0],表示服务器端口号; [lindex $argv 1],表示服务器名称; [lindex $argv 2],表示服务器 IP 地址; [lindex
1.expect是linux中一个交互命令,一般在 /usr/bin/expect路径下,如果该路径未加入到环境中需要先添加,其作用场景常用于交互执行输入指令 常用命令: expect.../usr/bin/expect #获取参数并设置局部变量 set timeout 15 set BASE_PATH [lindex $argv 0] set FILE_NAME [lindex $argv...1] set IP [lindex $argv 2] set TARGET_PATH [lindex $argv 3] #执行scp操作 spawn scp -P 16022 ${BASE_PATH}
有关expect命令的使用方法请见: shell脚本学习之expect命令 http://www.linuxidc.com/Linux/2014-02/96262.htm 有关实现Hadoop集群一键安装的步骤.../usr/bin/expect -f set timeout 300 set ip_addr [lindex $argv 0] set user [lindex $argv 1] set passwd...[lindex $argv 2] set newuser [lindex $argv 3] set newpwd [lindex $argv 4] spawn ssh "$user@$ip_addr"
工具安装 源代码和下载地址都是由 Linux 软件基金会维护的(sourceforge) # 因为Expect需要Tcl编程语言的支持 $ sudo yum install -y gcc $ sudo...$argv 0] set username [lindex $argv 1] set password [lindex $argv 2] set port [lindex $argv 3] spawn.../usr/bin/expect set IP [lindex $argv 0] set USER [lindex $argv 1] set PASSWD [lindex $argv 2]...$argv 1 ] set passwd [lindex $argv 2 ] set port [lindex $argv 3 ] set passphrase [lindex $argv...欢迎投稿,投稿邮箱: editor@hi-linux.com。 ? ?
expect 表达式 [动作] #示例 spawn ssh root@192.168.1.1 uptime expect "*password" {send *123456\r"} #提示:上述命令不能直接在linux...、 在expect中argv表示参数数组,可以使用[lindex argv n]接收expect脚本传参,n从0开始,分别表示第一个[lindex argv 0]参数、第二个[lindex argv 1.../usr/bin/expect set file [lindex $argv 0] set id [lindex $argv 1] set host [lindex $argv 2] puts "$file.../usr/bin/expect set file [lindex $argv 0] set id [lindex $argv 1] set host [lindex $argv 2] puts "$file.../usr/bin/expect set src_file [lindex $argv 0] set dst_file [lindex $argv 1] set host [lindex $argv 2
/usr/bin/expect # 使用 expect 结合 ssh 登录远程服务器 # 将传给脚本的参数赋值给变量 set sshPort [lindex $argv 0] set user [lindex...$argv 1] set ip [lindex $argv 2] set password [lindex $argv 3] # spawn 命令新启子进程,执行后面的命令 spawn ssh -p...grep ssh 远程服务器上查看 ssh 端口号,默认是 22 service sshd reload 重启 ssh 服务,因为可能需要改配置文件,如修改默认 22 端口 scp scp 命令用于 Linux...local/xxx.file # 上传当前目录下的文件到远程指定目录下 put xxx.file /usr/local/ 有一点需要注意,如果本机是 window 系统,那么在 window 系统和 linux.../usr/bin/expect # 将传给脚本的参数赋值给变量 set ip [lindex $argv 0] set port [lindex $argv 1] set user [lindex $
对于大规模的linux运维很有帮助 在linux运维和开发中,我们经常需要远程登录服务器进行操作,登录的过程是一个交互的过程,可能会需要输入yes/no,password等信息。...expect 匹配捕捉关键字 ——> 捕捉到将触发send 代替人为输入指令—> interact /expect eof $argv参数数组 Expect脚本可以接受从bash传递的参数,可以使用 [lindex.../usr/bin/expect //expect文件路径 set timeout 60 set hostname [lindex $argv 0] set...password [lindex $argv 1] spawn ssh root@$hostname expect { "(yes/no)" {send "yes\r";exp_continue} ".../usr/bin/expect //expect文件路径 set timeout 20 set hostname [lindex $argv 0] set
/usr/bin/expect set ip [lindex $argv 0 ] # 接收第1个参数,作为IP set username [lindex $argv 1 ] # 接收第2...个参数,作为username set password [lindex $argv 2 ] # 接收第3个参数,作为密码 set timeout 30 # 设置超时时间.../usr/bin/expect set IP [lindex $argv 0] set USER [lindex $argv 1] set PASSWD [lindex $argv 2]...set CMD [lindex $argv 3] spawn ssh $USER@$IP $CMD expect { "(yes/no)?"...{ send "yes\n";exp_continue } "password" { send "root\n" } } expect eof ---- 参考文献 expect(1) - Linux
expect依赖于tcl,而linux系统里一般不自带安装tcl,所以需要手动安装 下载:expect-5.43.0.tar和tcl8.4.11-src.tar 下载地址:https://pan.baidu.com...expect #sshkey.exp if {$argc<3} { puts stderr "Usage: $argv0 host user passwd " exit 1 } set host [ lindex...$argv 0 ] set user [ lindex $argv 1 ] set pwd [ lindex $argv 2 ] set timeout 30 #spawn ssh ${user}...{$argc<4} { puts stderr "Usage: $argv0 localfile remotefile user passwd " exit 1 } set localfile [ lindex...$argv 0 ] set remotefile [ lindex $argv 1 ] set user [ lindex $argv 2 ] set pwd [ lindex $argv 3 ]
/usr/bin/expect set user [lindex $argv 0] set host [lindex $argv 1] set passwd [lindex $argv 2] set file.../usr/bin/expect set user [lindex $argv 0] set host [lindex $argv 1] set passwd [lindex $argv 2] spawn.../usr/bin/expect set host [lindex $argv 0] set passwd [lindex $argv 1] set cm [lindex $argv 2] spawn ssh...syum $p done ###variables,fuctions mysql_5_1=http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux...mysql_5_7=http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-$ar.tar.gz ###########
Linux expect详解 2018-07-11 分类:Linux Shell / 系统运维 / 编程开发 阅读(6670) 评论(0) 随处可见的expect 第一次见expect这个命令还是我第一次参加全量上线的时候...先抛出一个问题 现在有两台Linux主机A和B,如何从A主机ssh到B主机,然后在B主机上执行命令,如何使这个过程实现全程自动化?...argc < 3} { puts "Usage:cmd " exit 1 } set timeout -1 set host [lindex...$argv 0] set username [lindex $argv 1] set password [lindex $argv 2] spawn ssh $username@$host expect..."*password*" {send "$password\r"} interact 在expect中,\$argc表示参数个数,而参数值存放在$argv中,比如取第一个参数就是[lindex $argv
工具安装 源代码和下载地址都是由 Linux 软件基金会维护的(sourceforge) # 因为Expect需要Tcl编程语言的支持 $ sudo yum install -y gcc $ sudo.../usr/bin/expect -d set timeout 30 spawn passwd [lindex $argv 1] set password [lindex $argv 2] expect...$argv 0] set username [lindex $argv 1] set password [lindex $argv 2] set port [lindex $argv 3] spawn.../usr/bin/expect set IP [lindex $argv 0] set USER [lindex $argv 1] set PASSWD [lindex $argv 2]...$argv 1 ] set passwd [lindex $argv 2 ] set port [lindex $argv 3 ] set passphrase [lindex $argv
set prompt [lindex $argv 0] set def [lindex $argv 1] set response $def set tout [lindex $argv...这里的expect其实和linux下的bash、windows下的cmd是一类东西。 注意:这一行需要在脚本的第一行。 2....admin spawn ssh root@192.168.1.130 Last login: Fri Sep 7 10:47:43 2012 from 192.168.1.142 [root@linux.../usr/bin/expect -f set ip [lindex $argv 0 ] set dir [lindex $argv 1 ] set file [lindex $argv...[lindex $argv 2] set src_file [lindex $argv 3] set dest_file [lindex $argv 4] spawn scp $src_file
if { [string trimright [lindex [split [lindex [split [version] "\n"] 1] "on"] 0]] == "SW Build 3365820...单板工作正常,能启动Linux,因此可以安全忽略。
/usr/bin/expect set timeout 30 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] expect...{send "yes\n";exp_continue} "password:" {send "[lindex $argv 3]\n"} } expect "~" send..."clear\n" interact 授权:sudo chmod 777 iterm2login.sh 这里[lindex $argv 0], [lindex $argv 1], [lindex $argv...2], [lindex $argv 3] 分别代表着4个参数。
/usr/bin/expect set timeout 30 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] expect...{send "yes\n";exp_continue} "password:" {send "[lindex $argv 3]\n"} } interact 这里[lindex...$argv 0], [lindex $argv 1],[lindex $argv 2], [lindex $argv 3] 分别代表着 端口号 用户名 服务器地址 密码 4个参数。
领取专属 10元无门槛券
手把手带您无忧上云