expect

how to escape unusual/uniq characters from expect scripts?

心已入冬 提交于 2021-02-16 20:14:28
问题 in expect script I can set any command or character to run it on remote machine but the sad thing is that expect cant send the same character as they defined in the expect script for example I want to run this line from expect script in order to change IP address from 10.10.10.10 to 1.1.1.1 expect # {send "perl -i -pe 's/\Q10.10.10.10\E/1.1.1.1/' /etc/hosts\r"} but when I run the expect screen actually I see this line runing on the console: [root@localhost ~]# perl -i -pe 's/Q10.10.10.10E/1.1

how to use shell variable in expect session?

你。 提交于 2021-02-08 11:57:29
问题 I try so send some files toward multiple servers using scp in bash script. But I encountering problem. here is the shell script I wrote. #!/bin/sh IP_LIST=('127.0.0.x' '127.0.0.y' '127.0.0.z') for ip_addr in "${IP_LIST[@]}" do echo "$ip_addr" expect << 'EOS' set timeout 10 spawn scp -p /home/foo/bar/baz.txt user@"$ip_addr":/home/destdir expect "*password*" send "pasword\r" expect eos exit 0 EOS done I assume each element in ip_addr is assigned to the variable ip_addr , but in expect session,

how to use shell variable in expect session?

假如想象 提交于 2021-02-08 11:57:21
问题 I try so send some files toward multiple servers using scp in bash script. But I encountering problem. here is the shell script I wrote. #!/bin/sh IP_LIST=('127.0.0.x' '127.0.0.y' '127.0.0.z') for ip_addr in "${IP_LIST[@]}" do echo "$ip_addr" expect << 'EOS' set timeout 10 spawn scp -p /home/foo/bar/baz.txt user@"$ip_addr":/home/destdir expect "*password*" send "pasword\r" expect eos exit 0 EOS done I assume each element in ip_addr is assigned to the variable ip_addr , but in expect session,

how to use regex in switch case in expect script?

本小妞迷上赌 提交于 2021-02-08 11:45:47
问题 Normally, switch case in expect looks like this: switch -- $count \ 1 { set type byte } 2 { set type word } big { set type array } default { puts "$count is not a valid type" } I need to use regex operators such as | or & - how can I do that? The below example does not work with expect code : switch -- $variable \ ("a"|"b"|"c") { do something } ("a"|"b"|"c") represents a or b or c, but it does not seem to work. How do I use such statements in switch or may be an and statement? 回答1: Use the

expect - telnet connection

谁说我不能喝 提交于 2021-02-08 08:20:30
问题 I'm trying to create a simple telnet connection script. I spawn telnet process. Depending on the version, it may or may not ask for password. After that It asks for username and password and rulese acceptation. After successful login it prompts for command. However, thing I wrote does not work. #/usr/bin/expect -f set IP [lindex $argv 0] set timeout 10 set send_slow {10 .5} log_user 1 spawn telnet -l cli $IP expect { timeout { puts "Network Connection Problem" close } "Password:" { send -s --

expect - telnet connection

偶尔善良 提交于 2021-02-08 08:19:36
问题 I'm trying to create a simple telnet connection script. I spawn telnet process. Depending on the version, it may or may not ask for password. After that It asks for username and password and rulese acceptation. After successful login it prompts for command. However, thing I wrote does not work. #/usr/bin/expect -f set IP [lindex $argv 0] set timeout 10 set send_slow {10 .5} log_user 1 spawn telnet -l cli $IP expect { timeout { puts "Network Connection Problem" close } "Password:" { send -s --

What can Expect do that Pexpect can not do?

南笙酒味 提交于 2021-02-08 04:37:26
问题 I am considering to start using Pexpect. On Pexpects homepage I find this: Q: Why not just use Expect? A: I love it. It's great. I has bailed me out of some real jams, but I wanted something that would do 90% of what I need from Expect; be 10% of the size; and allow me to write my code in Python instead of TCL. Pexpect is not nearly as big as Expect, but Pexpect does everything I have ever used Expect for. There is a 10% difference between Pexpect and Expect. So my question is what is this 10

Linux Expect waiting before exiting

隐身守侯 提交于 2021-02-04 21:47:39
问题 #!/usr/bin/expect # Test expect script to telnet. spawn telnet 192.168.1.1 expect "Username: " send "adminpldt\r" expect "Password: " send "password\r" expect "$" send "show lan\r" send "show\r" expect eof close # end of expect script. Here is the problem, when I run this code, it shows the correct output. But it doesn't exit afterwards, it's like waiting for an input. Like a timeout. But if I remove the line "EXPECT EOF". it terminates immediately. Can someone help me? I just started inLinux

Bash su expect combo

Deadly 提交于 2021-01-29 20:39:08
问题 I currently have a script to help me automate an install. During this install I have to switch from root to another user, gpadmin, and run the final leg of the install. At this point I call: su - gpadmin -c 'echo source /usr/local/greenplum-perfmon-web-4.1.2.0-build-2/gpperfmon_path.sh > .bashrc2; source ~/.bashrc2; gpperfmon --setup' This works but I have to manually go through the EULA and other parameters. I had used a here document to go through and finish everything but for some reason

How to toggle Tcl interact and expect for telnet automation?

纵然是瞬间 提交于 2021-01-29 15:59:48
问题 Similar to but different from autoexpect in that autoexpect will always produce the same output for any given input. Whereas, trying to allow for user input sometimes at least. This works in that it passes control back to the user as below: thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ tclsh main.tcl got nyc spawn telnet rainmaker.wunderground.com Trying 35.160.169.47... Connected to rainmaker.wunderground.com. Escape character is '^]'. --