expect

How to use bash script variables in expect conditional statements

一世执手 提交于 2019-12-06 02:25:40
问题 I am writing a bash script and using expect to do sftp. Now in the expect block I want to access a bash variable in a conditional statement. but, I am unable to do so. Can somebody help in this. Also, the execution of this script is controlled from a c prograame and i wan't redirect the output to a log file (which again is dynamic). Can i do that and suppress all teh output on stdout here is the code !/usr/bin/bash host=$1 user=$2 pass=$3 action=$4 path=$5 echo "Starting...." function

使用curl提交post请求到服务器被squid代理拦截

大城市里の小女人 提交于 2019-12-05 23:36:26
原文地址: http://dade.io/archives/25/ 做网盘,上传文件到服务器时(服务器使用squid做代理),遇到下面的错误提示: 百思不得其解,查看PHP文档时,笔记中发现如下说明: Sending a post file upload across a squid proxy, the request was rejected by the proxy. In the error page returned it provided among other possible causes:"Expect:" feature is being asked from a HTTP/one.zero. Solution: Add the option <?php curl_setopt($cl,CURLOPT_HTTPHEADER,array("Expect:")); ?>. This will remove the expect http header. 按照方案去掉“Expect:”的header头,OK! 文档还是挺有用的,希望能帮到各位! 来源: oschina 链接: https://my.oschina.net/u/197193/blog/169930

How to wait for a process to complete using tcl-expect

此生再无相见时 提交于 2019-12-05 22:14:37
问题 I am writing a script using expect in which I have to rlogin to some host & after that I need to send some commands. Now I want to exit to that host and relogin again to some other host and send some commands. But the run of my script is not waiting for first host to complete its jobs and exit instead it sends other commands in between the previous process. How can I achieve this using expect please guide? Sample code is as follow : #!/usr/local/bin/expect -f spawn rlogin host1 expect "%"

理论 :shell编程之expect免交互

纵饮孤独 提交于 2019-12-05 21:28:47
前言: expect用途: 设置账号密码 ssh输入登陆密码 scp 输入验证密码 免交互的目的是代人工手动输入 expect概述 expect安装 expect基本命令 expect执行方式 expect案例 一 : expect 概述 1.1 expect expect是建立在tcl基础上的一个工具,expect是用来进行自动化控制和测试的工具。主要解决shell脚本中不可交互的问题。对于大规模的linux运维很有帮助 在linux运维和开发中,我们经常需要远程登陆服务器进行操作,登陆的过程是一个交互的过程,可能会需要输入yes/no、password等信息。为了模拟这种输入,可以使用expect脚本 二 : expect 安装 2.1 挂载光盘 2.2 制作本地yum仓库 2.3 执行安装命令 yum install expect -y 系统在默认情况下是没有安装expect软件,需要手动安装 三 : expect基本命令 3.1 spawn : 启动进程,并跟踪后续交互信息 3.2 expect expect的一个内部命令,判断上次输出结果里是否包含指定的字符串,如果有则立即返回,否则就等待超过时间后返回。 只能捕捉由spawn启动的进程的输出 3.3 send :向进程发送字符串,用于模拟用户的输入 该命令不能自动回车换行,一般要加\r(回车) 3.4 interact

SSH in Java App with 'expect' like functionality [closed]

久未见 提交于 2019-12-05 20:25:51
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . With 'expect', one can execute SSH commands and parse the output of those commands to alter program flow. I'd like to do this with Java. That is, I want my Java app to launch a SSH session, execute a command on the remote server, and depend on the output of that command execute the next command,

bash: does expect work with multiple password prompts?

一个人想着一个人 提交于 2019-12-05 20:22:58
I am currently using expect to pass in passwords so my scripts can run automatically without me having to sit around and type in the same password over and over again. Important: Please don't comment about how big of a security risk this is or how I should be using ssh keys, I would use those if I could, but the setup I have to work with doesn't allow it. My code looks like the following: #!/bin/sh PASS=mypassword /usr/bin/expect -c " spawn python Tools/python/install.py expect -nocase \"password:\" {send \"$PASS\r\"; interact} " The problem I have is that install.py prompts for the same

shell脚本基础(七)

a 夏天 提交于 2019-12-05 19:08:45
一、分发系统介绍 当业务越做越大,服务器需求越来越多,几台服务器的话还好一点;当十几、几十台的时候,工作量就非常大!并且不规范,需要一个模板机分发到各个机器上去。 可以用开源的软件,expect脚本语言,进行实现分发系统的功能。 二、expect脚本远程登录 [root@zlinux-01 ~]# yum install -y expect //安装 [root@zlinux-01 sbin]# vim 01.expect //自动远程登录,并执行命令 #!/usr/bin/expect set host "192.168.242.129" #远程机器IP set passwd "rootroot" spawn ssh root@$host expect { "yes/no" {send "yes\r"; exp_continue} "assword:" {send "$passwd\r"} } interact #表示停留在机器上 #如果需要退出 可以expect eof [root@zlinux-01 sbin]# chmod a+x 01.expect //授予执行权限 您在 /var/spool/mail/root 中有新邮件 [root@zlinux-01 sbin]# ./01.expect //执行 spawn ssh root@192.168.242.129 The

shell脚本基础(八)

孤街浪徒 提交于 2019-12-05 19:08:38
一、expect脚本同步文件 [root@zlinux-01 ~]# cd /usr/local/sbin/ [root@zlinux-01 sbin]# ls 01.expect 02.expect 03.expect check_ng.sh lvs_dr.sh lvs_nat.sh mon nginx_log_rotate.sh [root@zlinux-01 sbin]# vim 04.expect //自动同步脚本 #!/usr/bin/expect set passwd "rootroot" spawn rsync -av root@192.168.242.129:/tmp/12.txt /tmp/ expect { "yes/no" { send "yes\r"} "password:" { send "$passwd\r"} } expect eof [root@zlinux-01 sbin]# ./04.expect spawn rsync -av root@192.168.242.129:/tmp/12.txt /tmp/ root@192.168.242.129's password: receiving incremental file list 12.txt sent 30 bytes received 84 bytes 228.00 bytes/sec

Problems with sudo inside expect script

烂漫一生 提交于 2019-12-05 18:05:53
I am running the following script #!/usr/bin/expect -f set user [lindex $argv 0] set pass [lindex $argv 1] set PATH [lindex $argv 2] set INV_PATH [lindex $argv 3] spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $user@localhost expect "assword: " send "$pass\r" expect "$ " send "echo $pass | /usr/local/bin/sudo -S $INV_PATH/orainstRoot.sh\r" expect "$ " send "cd $PATH/bin\r" expect "$ " send "echo $pass | /usr/local/bin/sudo -S cp oraenv coraenv sqlplus dbhome /usr/bin\r" expect "$ " send "echo $pass | /usr/local/bin/sudo -S $PATH/root.sh\r" expect "Check" send "\r" Its

expect免交互用法

半世苍凉 提交于 2019-12-05 17:03:54
一、ssh免交互远程连接linux服务器    ssh在远程连接linux系统时,会有交互,比如输入yes/no,或者需要输入密码。我们怎么避免这些交互呢!比如我们可以用telnet远程登录交换机,去备份交换机的配置,如果每一台都要手动输入密码,在有很多台交换机的情况下,这些交互就会显得很繁琐,或者我们需要自动备份这些交换机,在写脚本的时候也需要避免这些交互。现在我们来用expect这个工具来避免这些交互。 1.1、安装expect 命令: 1 [root@client yck]# yum -y install expect 2 [root@client yck]# rpm -q expect 3 expect-5.45-14.el7_1.x86_64 4 [root@client yck]# 5 [root@client yck]# 1.2、远程登录linux系统的脚本 脚本: 1 #!/usr/bin/expect #制定expect解释器 2 set ip [lindex $argv 0] #创建变量ip,并指定第一个位置变量 3 spawn ssh root@$ip #spawn创建一个回话,root用户远程连接 4 expect { 5 "yes/no" { send "yes\r";exp_continue } #捕捉到“yes/no”,就发送指令yes,\r表示回车