expect

save the result of ls command in the remote sftp server on local machine

孤者浪人 提交于 2020-01-16 01:07:12
问题 I have seen This question but I am not satisfied with answer. I connect to remote sftp server and I will do ls there I want to have the result of ls on my local machine. I don't want any thing extra to be saved, only the result of ls command. Can I save the result to a variable accessible on the local machine? #!/usr/bin/expect spawn sftp myuser@myftp.mydomain.com expect "password:" send "mypassword\n"; expect "sftp>" send "ls\n" //save here interact 回答1: Here's how I would do it, with a more

No glob expansion without -re option in Expect

南楼画角 提交于 2020-01-15 10:45:37
问题 #!/usr/bin/expect spawn passwd [lindex $argv 0] set password [lindex $argv 1] expect -nocase "pass*" { send "$password\r" } expect -nocase "password" { send "$password\r" } expect eof How can I prevent expect to expand the glob * in pass* ? This is just an example. In my actual code, I want to keep the glob, but I don't want to at -ex , which stands for exact match, or -re option for regex. 回答1: If you want a glob-style match, use the -gl option before it: expect { -gl -nocase "pass*" { # Do

No glob expansion without -re option in Expect

寵の児 提交于 2020-01-15 10:44:05
问题 #!/usr/bin/expect spawn passwd [lindex $argv 0] set password [lindex $argv 1] expect -nocase "pass*" { send "$password\r" } expect -nocase "password" { send "$password\r" } expect eof How can I prevent expect to expand the glob * in pass* ? This is just an example. In my actual code, I want to keep the glob, but I don't want to at -ex , which stands for exact match, or -re option for regex. 回答1: If you want a glob-style match, use the -gl option before it: expect { -gl -nocase "pass*" { # Do

Bash Script: Send files to SFTP using Expect

╄→尐↘猪︶ㄣ 提交于 2020-01-15 07:30:27
问题 I have to send few gzipped files from local server to SFTP server. My Server Info Distributor ID: Ubuntu Description: Ubuntu 12.04.4 LTS Release: 12.04 Codename: precise Created a bash script and could able to send files to sftp, but i want to send email if transfer is successful. #!/bin/bash HOST=hostname.domain PORT=22 USER=username PASSWORD=password SOURCE_FILE=path/filename TARGET_DIR=PATH /usr/bin/expect<<EOD spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST expect "password:" send "

How to store output in a variable while using expect 'send' command

时间秒杀一切 提交于 2020-01-14 07:43:08
问题 Thanks. But the account and password are needed. So I must send them and then send ovs-vsctl command. the scripts are something like this: spawn telnet@ip expect -re "*login*" { send "root" } expect -re "password*" { send "****" } send "ovs-vsctl *******" I want to store the output of this command send "ovs-vsctl ****" , but many times I got some output of the command "send "password"", how can I get the output of send "ovs-vsctl****" . The output of the command send "ovs-vsctl *** are two

Pass bash array to expect script

烈酒焚心 提交于 2020-01-14 03:42:07
问题 I have a bash script that calls an expect script like so $SCRIPTS_DIRECTORY/my_expect_script.sh $my_bash_array I can pass a variable over, it seems, and use it. For this example the variable seems to be in [lindex $argv 0] . From bash, it will be a bunch of values, e.g. 1 2 3 4 5 . I am trying to figure out how to use expect to grab this variable, save it to an array then loop through the array to spit out multiple commands one at a time. So my output should be something like send command 1

gulp常用插件之chai使用

眉间皱痕 提交于 2020-01-13 13:18:36
更多gulp常用插件使用请访问: gulp常用插件汇总 chai 这是一款用于节点和浏览器的BDD / TDD断言库,可以与任何javascript测试框架完美地配对。 更多使用文档请点击访问chai工具官网 。 安装 一键安装不多解释 npm install --save-dev chai 使用 浏览器 您也可以在浏览器中使用它。通过npm安装并使用chai.js下载中找到的文件。例如: <script src="./node_modules/chai/chai.js"></script> 导入库中的代码,然后挑选的款式之一,你想使用-要么 assert , expect 或 should : var chai = require('chai'); var assert = chai.assert; // 使用断言样式 var expect = chai.expect; // 使用Expect样式 var should = chai.should(); // 使用Should样式 本机模块用法(在全球注册chai测试样式) require('chai/register-assert'); // 使用断言样式 require('chai/register-expect'); // 使用Expect样式 require('chai/register-should'); //

Problems with sudo inside expect script

烈酒焚心 提交于 2020-01-13 11:06:02
问题 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"

纠结了好几天的GMock学习小结

≡放荡痞女 提交于 2020-01-13 07:12:31
这周project中遇到了用GMock实现的unit test,看了doc依旧很迷,今天终于想明白了,在此记录一下。 首先,为什么需要GMock,只用GTest不行吗? GTest作为unit test很好理解,即为test一个函数end to end的输入输出对不对,例如 int Factorial(int n); // Given an input n, returns the result of n!. EXPECT_EQ(Factorial(2), 2); EXPECT_EQ(Factorial(1), 1); 可以测试Factorial()函数的结果是否正确。 但是GTest只可test函数的输出,无法test函数内部的情况。对于以下例子 class Oiginal { void InnerFuncA(); void InnerFuncB(); bool OuterFunc(string name, bool flg) { cout << "My name is: " << name <<endl; if(flg) { InnerFuncA(); } else { InnerFuncB(); } return random() > 0.5 ? true : false; } }; 我们想check当flg == true时,调用的是InnerFuncA(),flg ==

java并发-原子性

走远了吗. 提交于 2020-01-10 19:30:41
原子性就是指该操作是不可再分的。 java.util.concurrent.atomic中有一组使用无锁算法实现的原子操作类。AtomicInteger、AtomicBoolean、AtomicLong 外还有 AtomicReference 。它们分别封装了对整数、整数数组、长整型、长整型数组和普通对象的多线程安全操作。 这些都是居于CAS算法实现的。CAS即:Compare and Swap,是比较并交换的意思。 CAS 简介 CAS有3个操作数,内存值V,旧的预期值A,要修改的新值B。当且仅当预期值A和内存值V相同时,将内存值V修改为B,否则什么都不做。 非阻塞算法 (nonblocking algorithms) 一个线程的失败或者挂起不应该影响其他线程的失败或挂起的算法。 现代的CPU提供了特殊的指令,可以自动更新共享数据,而且能够检测到其他线程的干扰,而 compareAndSet() 就用这些代替了锁定。 拿出AtomicInteger来研究在没有锁的情况下是如何做到数据正确性的。 private volatile int value; 首先毫无以为,在没有锁的机制下可能需要借助volatile原语,保证线程间的数据是可见的(共享的)。 这样才获取变量的值的时候才能直接读取。 public final int get() { return value; } 然后来看看