expect

Bash/Expect Script for SSH

柔情痞子 提交于 2019-12-19 02:05:35
问题 I am new to expect and scripting in general. I am trying to make a few scripts to make my life a bit easier when pulling network device configurations. I managed to create a basic expect script to SSH to a device and save the configuration. I want to expand upon this and allow the script to connect to a number of IP addresses instead of just one like I have right now. I have a file named list.txt with a few different IP addresses with each IP on a separate line. What would I need to do to

When to Expect and When to Stub?

心不动则不痛 提交于 2019-12-18 12:23:48
问题 I use NMock2, and I've drafted the following NMock classes to represent some common mock framework concepts: Expect : this specifies what a mocked method should return and says that the call must occur or the test fails (when accompanied by a call to VerifyAllExpectationsHaveBeenMet() ). Stub : this specifies what a mocked method should return but cannot cause a test to fail. So which should I do when? 回答1: A lot of mocking frameworks are bringing the concepts of mocks & stubs closer & closer

Windows上安装配置SSH教程(1)

坚强是说给别人听的谎言 提交于 2019-12-18 11:26:14
作者: feipeng8848 出处: https://www.cnblogs.com/feipeng8848/p/8559803.html 本站使用「 署名 4.0 国际 」创作共享协议,转载请在文章明显位置注明作者及出处。 1.是什么SSH? 维基百科: https://zh.wikipedia.org/wiki/Secure_Shell 其他博客: http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html 总结一下就是:SSH(Secure Shell)是一种加密的网络传输协议,常用于远程登陆与远程文件传输。使用SSH能有效避免数据在传输过程中被窃取篡改。SSH可以采用密码方式登陆远程,也可以使用公钥私钥自动登陆。 SSH是一种协议,该协议的实现有很多种,OpenSSH就是其中一种,OpenSSH是自由软件,可免费使用。 2.什么是OpenSSH( OpenBSD Secure Shell )?如何在计算机上安装OpenSSH OpenSSH是SSH协议的一种实现,在计算机上安装完OpenSSH并开启服务后该计算机就可作为SSH服务器被远程访问和上传下载文件。 OpenSSH官网: https://www.openssh.com/ 在计算机上安装与配置OpenSSH教程: http://www.cnblogs

SSh client in C# .net

风格不统一 提交于 2019-12-18 09:05:40
问题 I want to write a program that accesses my routers and perform some command, while its output is save to file on my disk. I have done this successfully using python pexpect module in linux. I am starting C# .net and want to try over it. Searching google gave me some result on ssh client, but i dont know if any of them can get me the result back ? Any ideas, i know i shouldnt be asking for any code snippet, just point me in right direction specially if someone has used it to fetch

Embedding an expect inside a bash script

天涯浪子 提交于 2019-12-18 04:23:13
问题 I realise similar questions have been asked before, I looked at them and tried to apply what I learned and have the following script: #!/bin/bash if [ `hostname` = 'EXAMPLE' ] then /usr/bin/expect << EOD spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/ expect "id_rsa':" send "PASSWORD\r" interact spawn scp -rp host:~/errfiles/ /home/USERNAME/errfiles/ expect "id_rsa':" send "PASSWORD\r" interact expect eof EOD echo 'Successful download' fi Unfortunately it doesn't seem to work and I

Simplest way to run an Expect script from Python

烂漫一生 提交于 2019-12-17 18:30:33
问题 I'm trying to instruct my Python installation to execute an Expect script "myexpect.sh": #!/usr/bin/expect spawn ssh usr@myip expect "password:" send "mypassword\n"; send "./mycommand1\r" send "./mycommand2\r" interact I'm on Windows so re-writing the lines in the Expect script into Python are not an option. Any suggestions? Is there anything that can run it the way "./myexpect.sh" does from a bash shell? I have had some success with the subprocess command: subprocess.call("myexpect.sh",

expect script to automate telnet login

六眼飞鱼酱① 提交于 2019-12-17 12:59:08
问题 I have been trying to create an expect script to automatically login to my device through telnet If there are no multiple possibilities for the expect command , the script works fine, logs in to the device. #!/usr/bin/expect set timeout 20 set ip [lindex $argv 0] set port [lindex $argv 1] set user [lindex $argv 2] set password [lindex $argv 3] spawn telnet $ip $port expect "'^]'." sleep .1; send "\r"; sleep .1; expect "login:" send "$user\r" expect "Password:" send "$password\r"; interact The

mac iterm2 expect 方式sz rz 失效

最后都变了- 提交于 2019-12-15 23:56:29
用的Mac,iterm2 登录服务器,写的脚本登录服务器,里面用到了expect命令。 Mac和服务器都安装了sz rz 工具,但是用sz从服务器下载文件,一直处于假死的状态,虽然提示了文件传输成功,但是到本地文件夹也没找到。从网上找了一下发现是 expect命令会造成 sz rz 失效。因此找了以下解决方案。 这里提到了一个解决方案: https://blog.csdn.net/lovewebeye/article/details/85049423 照着弄了下。 新建一个脚本,输入以下内容 #!/bin/sh #basepath=$(cd `dirname $0`; pwd) export LC_CTYPE=en_US #expect脚本所在位置 #filepath=$basepath/XXX.sh exec 脚本的绝对路径 主要是加了一个export LC_CTYPE=en_US 然后在这个脚本里执行了我们真正的登录脚本。 Mac iterm2 使用expect后无法使用lrzsz 指令,上传不报错,文件也没有 关于怎么这只rz sz 支持 https://blog.51cto.com/fulin0532/1926254 来源: 51CTO 作者: 努力的C 链接: https://blog.51cto.com/fulin0532/2439271

expect 使用案例

核能气质少年 提交于 2019-12-14 14:43:06
本文用一个最短的例子说明脚本的原理。   脚本代码如下:   ##############################################   #!/usr/bin/expect   set timeout 30   spawn ssh -l username 192.168.1.1   expect "password:"   send "ispass\r"   interact   ##############################################   1. [#!/usr/bin/expect]   这一行告诉操作系统脚本里的代码使用那一个shell来执行。这里的expect其实和linux下的bash、windows下的cmd是一类东西。   注意:这一行需要在脚本的第一行。   2. [set timeout 30]   基本上认识英文的都知道这是设置超时时间的,现在你只要记住他的计时单位是:秒   3. [spawn ssh -l username 192.168.1.1]   spawn是进入expect环境后才可以执行的expect内部命令,如果没有装expect或者直接在默认的SHELL下执行是找不到spawn命令的。所以不要用 “which spawn“之类的命令去找spawn命令

Sed does not work in expect

不羁的心 提交于 2019-12-14 04:07:18
问题 I made this bash one-liner which I use to list Weblogic instances running along with their full paths.This works well when I run it from the shell. /usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed 's/weblogic.policy//' | sed 's/security\///' | sort I tried to incorporate this in an expect script send "echo Weblogic Processes: ; /usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '