expect

Making decisions on expect return

吃可爱长大的小学妹 提交于 2020-02-06 11:12:10
问题 I am trying to create an expect script which will send a different password string based on the "expect" Condition A: If a cisco device has not been setup with a username then the first prompt will simply be "Password:" - then it should use passwordA (no username) Condition B: If it has been setup with a username then the prompt will be "Username:" followed by "Password:" - then it should use Username and PasswordB #!/bin/bash # Declare host variable as the input variable host=$1  # Start the

mac上安装expect实现ssh自动登录

有些话、适合烂在心里 提交于 2020-02-05 09:10:09
必备软件 tcl 或 https://download.csdn.net/download/hbj206/12080241 expect 或: https://download.csdn.net/download/hbj206/12080247 下载软件的地址建议使用浏览器直接下载,下载的文件为*.tar文件,使用下载软件下载的*.tar.gz可能会出现问题。 下载后的*.tar文件建议解压放在 /usr/local 目录下。 1. 配置tcl 解压&&编译 tar -xvf tcl8.6.10.tar cd tcl8.6.10 cd unix sudo ./configure --prefix=/usr/local/tcl sudo make sudo make install sudo cp ./tclUnixPort.h ../generic/ 2.配置expect 解压&&配置 sudo tar -xvf expect5.45.4.tar cd expect5.45.4 sudo ./configure --prefix=/usr/local/expect --with-tcl=/usr/local/tcl/lib --with-tclinclude=/usr/local/tcl8.6.10/generic sudo make sudo make install 3

第十周

点点圈 提交于 2020-02-05 00:49:32
1.编写脚本selinux.sh,实现开启或禁用SELINUX功能 #!/bin/bash while read ip user password;do expect <<EOF set timeout 20 spawn ssh $user@$ip expect { "yes/no" { send "yes\n";exp_continue } "password" { send "$password\n" } } expect "]#" { send "sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config\n" } expect "]#" { send "exit\n" } expect eof EOF done < user.txt 2.统计/etc/fstab文件中每个文件系统类型出现的次数 awk '/UUID/{print $3}' /etc/fstab |sort|uniq -c 3.提取出字符串Yd$C@M05MB%9&Bdh7dq+YVixp3vpw中的所有数字 echo "Yd$C@M05MB%9&Bdh7dq+YVixp3vpw"|awk 'gsub(/[^0-9]/,"")' 4.解决DOS攻击生产案例:根据web日志或者或者网络连接数,监控当某个IP

curl post请求总是返回417错误

随声附和 提交于 2020-02-03 00:43:46
在进行post请求的时候, curl总是返回417错误 在使用curl做POST的时候, 当要POST的数据大于1024字节的时候, curl并不会直接就发起POST请求, 而是会分为俩步。 发送一个请求, header包含一个Expect:100-continue, 询问Server使用愿意接受数据 接收到Server返回的100-continue应答以后, 才把数据POST给Server 但是,并不是所有的server都支持expect这个头,就会返回417错误, 所以在curl的时候,需要禁止expect试探。 如下: struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Expect:"); //禁止curl的试探 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); // 设置GET请求参数 转载请注明出处哦。给你科普技术 http://www.cnblogs.com/stonehat/ 来源: https://www.cnblogs.com/stonehat/p/6923396.html

Expect:100-Continue & HTTP 417 Expectation

人走茶凉 提交于 2020-02-03 00:41:27
背景: 今天调试火车票查询的代码,发现一个奇怪的事情,如果使用公司本地的代理,那么一切正常,如果使用的是公司台湾的代理,那么将出现以下错误 :“The remote server returned an error.(417) Unkown”。 很是奇怪啊,为什么换了服务器后,效果完全相反。反复查阅代码最终找出关键点,HTTP协议。 1.分析bug的原因 看着VS2010的错误信息: (417) Unkown 。 有一点经验的人就会联想到HTTP200啊,等等之类的东西。那个HTTP协议中的内容那么多,到时是哪一个属性出现的问题呢,我决定用wireshark抓包,进行比较。对比结果:用台湾代理时,抓包的结果中多处了一下字符串 “‍Expect:100-Continue”。( wireshark使用 ) 于是查看关于HTTP1.1的相关网页。 HTTP1.1协议中文版-RFC2616 和 HTTP1.1协议英文版-RFC2616 在上两篇文章中可以看到以下一段描述: The purpose of the 100 (Continue) status (see section 10.1.1 ) is to allow a client that is sending a request message with a request body to determine if the

关于HTTP请求返回417 “Expectation Failed”

淺唱寂寞╮ 提交于 2020-02-02 23:15:27
在使用HttpClient 默认情况下 做POST的时候, HttpClient 并不会直接就发起POST请求, 而是会分为俩步, 1.发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据, 2.接收到Server返回的100-continue应答以后, 才把数据POST给Server 于是,这样就有了一个问题, 并不是所有的Server都会正确应答100-continue, 比如lighttpd, 就会返回417 “Expectation Failed”, 则会造成逻辑出错 Expect:100-Continue握手的目的,是为了允许客户端在发送请求内容之前,判断源服务器是否愿意接受 请求(基于请求头部)。 Expect:100-Continue握手需谨慎使用,因为遇到不支持HTTP/1.1协议的服务器或者代理时会引起问题。 而HttpClient 4.0中,是否激活Expect:100-Continue,是由HTTP请求执行参数http.protocol.expect-continue来控制的,通过设置参数值为true或者false,可以相应的激活或者关闭Expect:100-Continue握手。注意, 在HttpClient中,默认是激活的。 我们来看看Http1.1协议中关于这个的说明吧。 (100状态码(见10.1.1节

postman——预处理和断言

浪尽此生 提交于 2020-01-31 05:19:47
一、预处理 Pre-request Scrip  1、Pre-request Script是集合中请求发送之前需要执行的代码片段   2、请求参数中包含一个随机数或者请求header中包括一个时间戳,或者你的请求参数需要加密 Pre-request Script常用代码   右侧提供了一些常用的代码       二、断言   postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可。   断言会在请求返回之后,运行,并根据断言的pass\fail情况体现在最终测试结果中。    clear a global variable 清除全局变量 pm.globals.unset("variable_key"); Clear an environment variable 清除环境变量 pm.environment.unset("variable_key"); get a global variable 得到一个全局变量 pm.globals.get("variable_key"); get a variable 得到一个变量 pm.variables.get("variable_key"); Get an environment variable 得到一个环境变量 pm.environment.get("variable_key"); response

except实现跳板机穿透登陆远程服务器

泪湿孤枕 提交于 2020-01-28 17:44:03
前言 公司有多台服务器,必须先登录跳板机,再从跳板机登录服务器,频繁的输入命令很繁琐,有没有更好的方式去实现。 expect 可以完美的帮助你 涉及概念 Tcl : (Tool command language)一种很强大的脚本语言 expect : 基于Tcl开发的语言包,请自行安装 except核心命令 send :命令向进程发送字符串。 expect :命令等待进程的某些字符串。expect支持正规表达式并能同时等待多个字符串,并对每一个 字符串执行不同的操作。expect还能理解一些特殊情况,如超时和遇到文件尾。 spawn :激活一个Unix程序来进行交互式的运行。 interact :允许用户交互 send命令用法 send "hello god.wei" 输出 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-C0BZ7A7K-1580201367165)(/img/bVbk79E)] send命令会直接将字符串发送到进程 那如果我要运行命令呢,可以这样 send "pwd\r" expect命令 用于接受进程的输出,然后我们可以通过判断输出结果来执行不同的操作 expect patlist1 action1 patlist2 action2… 该命令一直等到当前进程的输出和以上的某一个模式相匹配,或者等到时间超过一个特定的时间长度

前端自动化测试jest教程8-snapshot快照测试

孤者浪人 提交于 2020-01-28 03:11:28
准备条件 以第1节教程的创建的目录和代码为基础进行讲解。如果没有看过第1节教程,请关注我,查看以往该系列的文章 这节教程主要讲解在jest中的怎样进行快照测试,将第1节的代码复制一份,并且把 index.js 和 index.test.js 文件内容全部清空 在 index.js 中写入一些待测试方法 export const data1 = ( ) => { return { name : 'Jsoning' , age : 26 , time : '2020.1.1' } } export const data2 = ( ) => { return { name : 'Jsoning' , age : 26 , time : new Date ( ) } } 在 index.test.js 中写入一些测试实例 import { data1 , data2 } from "./index" it ( '测试快照 data1' , ( ) => { expect ( data1 ( ) ) . toMatchSnapshot ( { name : 'Jsoning' , age : 26 , time : '2020.1.1' } ) } ) it ( '测试快照 data3' , ( ) => { expect ( data2 ( ) ) . toMatchSnapshot (