expect

Regular Expression to find string in Expect buffer

China☆狼群 提交于 2019-12-20 05:11:27
问题 I'm trying to find a regex that works to match a string of escape characters (an Expect response, see this question) and a six digit number (with alpha-numeric first character). Here's the whole string I need to identify: \r\n\u001b[1;14HX76196 Ultimately I need to extract the string: X76196 Here's what I have already: interact { #... #... #this expression does not identify the screen location #I need to find "\r\n\u001b[1;14H" AND "([a-zA-Z0-9]{1})[0-9]{5}$" #This regex was what I was using

Execute sudo using expect inside ssh from bash

吃可爱长大的小学妹 提交于 2019-12-20 05:01:36
问题 I want to create a script that automates a installation on multiple linux hosts. I login to the hosts using ssh keys and inside the login I want to do a sudo, I am trying to use expect, which I have on the stations but I don't have on the server which runs the script. How do I do this, this is my try, but no luck with it: #!/bin/bash ssh user@station04 <<EOF expect -d -c " send \"sudo ls\" expect { \"password:\" { send '1234'; exp_continue } \"$user@\"{ send "exit\r" } default {exit 1} }" EOF

Jest 测试框架

﹥>﹥吖頭↗ 提交于 2019-12-20 04:07:49
jest 是facebook推出的一款测试框架,集成了 Mocha,chai,jsdom,sinon等功能。 安装与配置 npm install --save-dev jest npm install -g jest 运行命令 jest 后会自动运行项目下所有 .test.js和 .spec.js这种格式的文件。涉及到运用 ES 或 react 的,要与babel相结合,加上.babelrc文件即可。jest的配置默认只需要在package.json中配置即可,当然也可以用独立的配置文件。 我们这里直接将 jest 的运行范围限定在test文件夹下,而不是全部,所以在package.json中加入如下配置: "jest": { "testRegex": "/test/.*.test.jsx?$" } 注意到这里的匹配规则是正则表达式 基本用法 和之前介绍的 mocha 和 chai 的功能很像,甚至可以兼容部分 mocha 和 chai 的语法。可以这么写 import React from 'react' import { shallow } from 'enzyme' import CommentItem from './commentItem' describe('测试评论列表项组件', () => { // 这是mocha的玩法,jest可以直接兼容 it(

how to use a shell script to supply a password when the interface asks for it

折月煮酒 提交于 2019-12-20 04:07:07
问题 I have a script( dobrt ) which upon executing asks for a password.How can i write a script which executes dobrt and automatically supplies the password it asks for. when i execute ./dobrt -p file.txt , the system asks for a password. I want the password to be sent in automatically by the script. Here is the output $ ./dobrt -p file.txt Found 194 tests to execute ------------ 2010 February 11 11:27:33 ------------ Password: *************** I tried using shell and expecxt scripts for this. here

Regular expressions in expect

强颜欢笑 提交于 2019-12-20 02:12:37
问题 I just started learning expect scripting.I have been trying to extract the following from my output: core.4046140998.01.10.133211 with an expect script using the following command.can somebody please tell me where I am going wrong?I want to get to store this entire string i.e.( core.4046140998.01.10.133211*) in a variable and perform some action with it. expect -re {^(core)\.*} {puts $expect_out(0,string)} Do i have to import any packages in expect to make this work? 回答1: Since this is expect

Expect - get variable from screen region based on row and column

丶灬走出姿态 提交于 2019-12-20 02:12:30
问题 I'm auto-interacting with an SSH session and an ERP program using Expect. Rather than relying on a regular expression to capture a variable in my expect script would it be possible upon receiving a certain keystroke from a user to capture a screen region, say one field, into a variable in the code? Send the server some other commands and resend the field? Say an order number is contained at 6, 12, 6, 18 (where 6 is the row and 12-18 are the columns) containing my 6 digit order number. I want

Usage of expect command within a heredoc

泪湿孤枕 提交于 2019-12-19 21:56:08
问题 For the following tiny expect script for which a function was added to the bash profile: chai() { expect <<- EOF spawn ssh myuser@myserver expect ': $' send 'mypassword\r' EOF } We get: bash: /etc/profile: line 409: syntax error: unexpected end of file What is wrong with that script? 回答1: I would normally expect the heredoc terminator (EOF) to be at the start of the line e.g. chai() { expect <<- EOF spawn ssh myuser@myserver expect ': $' send 'mypassword\r' EOF } I see you're using <<- and

Apache [PTY Errors] in cgi-perl file while creating a new Expect object

◇◆丶佛笑我妖孽 提交于 2019-12-19 11:53:37
问题 I have a perl script: #!/usr/bin/perl -w use DateTime; use Expect; use IO::Pty; use CGI::Fast; while($q = new CGI::Fast){ my $ip = $q->param('ip'); my $folder = $q->param('folder'); my $username = $q->param('username'); my $password = $q->param('password'); print "Content-type: text/html\r\n\r\n"; print "<head>\n<title>FastCGI</title>\n\</head>"; print "<h3> $ip - $folder - $username - $password </h3>"; my $ssh = new Expect; if($ssh->spawn("ssh -q -l $username $ip")){ print "<h4>Connexion OK<

How to change current work directory using expect script?

南楼画角 提交于 2019-12-19 10:25:38
问题 I want to write an expect script which can do some task and in the end change the directory and give control to the user. I tried using spawn cd path\to\dir interact but i am still in the same directory. Any leads on how to accomplish this using expect ? 回答1: I suppose you have spawn ed some command (like ssh , bash ) and the spawn ed command is still running. Then at the end you can do like this: send "cd /some/dir\r" interact 回答2: To change the directory in an expect script, you don't need

How to use a variable in regexp expression (TCL/Expect)

℡╲_俬逩灬. 提交于 2019-12-19 08:50:35
问题 I'm trying to figure out how to use a string in a regexp match. I have been searching on google for an hour, figured i would just ask the experts. This works: #!/usr/bin/expect set MYSTR "value" if [ regexp -nocase "$MYSTR" $outcome matchresult ] then { ... } This is not working: #!/usr/bin/expect set MYSTR "value" if [ regexp -nocase {something here:\s+$MYSTR} $outcome matchresult ] then { ... } I'm sure it's a simple syntax problem. Thanks for your help 回答1: Right. You have 2 options: