expect

Handle multiple Spawn process in expect script

坚强是说给别人听的谎言 提交于 2019-12-04 06:07:10
问题 Here is my use case for expect script ( one of few i have) I want to run multiple sed command over ssh. Its like pre-build environment setup. I want to run something like this :- #!/usr/bin/expect set timeout -1 spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff1> <file1>'" spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff2> <file2>'" spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff3> <file3>'" expect { -re ".*sword.*" { exp_send "$env(PASS_WORD)\n" exp_continue

快捷使用 Iterm2 连接SSH

我的未来我决定 提交于 2019-12-04 04:17:35
1,配置iterm2 > Preferences.. > Profiles > 填写:name : 别名 ; Command : expect /Users/jerryxu/wwwroot/cache/bin/ssh_jwy 2,/Users/jerryxu/wwwroot/cache/bin/ssh_jwy 内容如下: #!/usr/bin/expect -f set port <port> set user <user> set host <ip> set password <pass> set timeout -1 spawn ssh -p $port $user@$host expect "*assword:*" send "$password\r" interact expect eof user 用户名 pass 密码 port 端口 ip 服务器ip或域名 3,右键iterm2 new tab/new window 打开别名连接。完成; 以上只适用于mac 使用配置; 如其它系统使用请对其配置相应更改即可; 当我们希望使用优秀的网络HTTP来代理连接ssh时: 首先安装 corkscrew brew install corkscrew 然后查看 corkscrew 位置: which corkscrew 得到的 corkscrew Path 后。如:/usr

Why do I get a segmentation fault in my simple c++ program using libexpect.so?

China☆狼群 提交于 2019-12-04 04:01:11
I am busy with a project where I have to automate some processes in bash or ssh so I decided to use the libexpect.so library. If you don't know what libexpect is, it provides an expect extension that I can use in a c++ program, and expect is just a program where you can run automated scripts for things like ssh. So I can execute a script which attempts to ssh somewhere...when the password prompt is found by expect I could have already given expect a password to send. My problem is that when I run a program, even a really simple one, I get a segmentation fault which I narrowed down, with gdb,

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

可紊 提交于 2019-12-04 03:50:05
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 "%" send "source xyz.csh\r" send "exit\r" expect "%" spawn rlogin host2 some set of commands Can you elaborate

Expect: extract specific string from output

空扰寡人 提交于 2019-12-03 22:06:26
问题 I am navigating a Java-based CLI menu on a remote machine with expect inside a bash script and I am trying to extract something from the output without leaving the expect session. Expect command in my script is: expect -c " spawn ssh user@host expect \"#\" send \"java cli menu command here\r\" expect \"java cli prompt\" send \"java menu command\" " ###I want to extract a specific string from the above output### Expect output is: Id Name ------------------- abcd 12 John Smith I want to extract

gets not waiting for user input in expect script

て烟熏妆下的殇ゞ 提交于 2019-12-03 15:38:18
When i try to run the following expect script, it just finishes running instead waiting for user input. Could someone tell me what i am doing wrong? #!/usr/bin/expect puts -nonewline stdout "Enter device id:" flush stdout gets stdin id puts -nonewline stdout "Enter device name:" flush stdout gets stdin name Expect alters the Tcl gets command so that it doesn't wait for standard input; to read a line while waiting for it, you need to do this instead of gets stdin id : # Read input to stdin expect_user -re "(.*)\n" set id $expect_out(1,string) Try this code : expect "\\$" puts -nonewline "please

Expect - Interrupt program - Ctrl+C

空扰寡人 提交于 2019-12-03 13:34:20
问题 I am running the following script to start a capture on a remote server and download the file afterwards. Currently I have to pause it with Ctrl + C and manually exit. How can I replace the interact and define a trigger to kill the tcpdump or catch the Ctrl + C and pass it inside the remote server? spawn ssh "$user_ssh\@$ssh_server" expect { "*password" { send "$pass\n"; exp_continue} "root\@*" { } timeout { puts "time out expecting password or bash"; exit 1 } } send "sudo tcpdump -i $intf

How can I encrypt or hide passwords in a Perl script?

半世苍凉 提交于 2019-12-03 12:34:41
I am working on Perl script that uses Expect to login via telnet to remote machines (don't ask, gotta use telnet). I also do perforce p4 login operations as necessary and use expect to pipe in the correct passwords. For now I just read passwords from clear text environment variable, i.e. export PASSWORD=password , which I know is no good security wise. What's the best way to store passwords for scripts like these that need a lot of passwords for multiple systems? Encrypted in a text file somehow? Or something else? Keep in mind I can't easily change the existing systems, like for example I can

复制密钥到目标机器

徘徊边缘 提交于 2019-12-03 12:05:08
##1.shell脚本 #!/bin/sh BASE_DIR=`dirname $0` && cd $BASE_DIR function ssh_copy_id(){ for ip in `cat .ips-other`;do expect auto-ssh-copy-id.exp $ip container `cat .password` if [ $? -ne 0 ]; then echo "免认证失败" fi done } ##2.expect脚本 #!/usr/bin/expect set timeout 5 set ip [lindex $argv 0] set user [lindex $argv 1] set password [lindex $argv 2] #复制密钥到目标机器 spawn ssh-copy-id $user@$ip -p 1433 expect { "yes/no" {send "yes\r";exp_continue;} "password" {send "$password\r";exp_continue;} } 来源: https://www.cnblogs.com/fan-gx/p/11795507.html

How to use expect with optional prompts?

笑着哭i 提交于 2019-12-03 11:53:24
问题 Let's say I am trying to write an expect script for a test.sh that has three prompts: prompt1, prompt2, prompt3. My code is like this: spawn test.sh expect "prompt1" send "pass1" expect "prompt2" send "pass2" expect "prompt3" send "pass3" However, prompt2 only occurs half the time. If prompt2 doesn't show up, the expect script breaks. How would I write expect code that skips over prompt2 if it doesn't show up? EDIT: Fixed my code: /usr/bin/expect -c ' spawn ./test.sh expect { "prompt1" { send