expect

expect script for remote ssh login and executing commands

[亡魂溺海] 提交于 2019-12-06 10:35:00
I am using following expect script for remote ssh login to raspberry pi and executing command #!/usr/bin/expect set timeout 60 spawn ssh [lindex $argv 1]@[lindex $argv 0] expect "yes/no" { send "yes\r" expect "*?assword" { send "[lindex $argv 2]\r" } } "*?assword" { send "[lindex $argv 2]\r" } expect "pi@raspberrypi ~ $ " { send "ls -la\r" } interact The problem is that this script is able to login into raspberry but when it comes to line for executing "ls -la" command nothing happens. Can anyone help me out with this script? Where I am making mistake? ok if I put exp_internal 1 line in my

Exit status code for Expect script called from Bash

孤街浪徒 提交于 2019-12-06 09:45:49
I made a Bash script which uses an expect script to automate ssh logins.The script connects to multiple servers and runs some commands. The bash script prompts for login credentials once. I want to incorporate a feature wherein the script terminates if the login fails for the first server to avoid the script checking for next servers resulting in the user account getting locked. The account lockout happens for 3 consecutive login failures and the number of server the script tries to connect is more than 3. This is the snippet in the bash script which calls the expect script. countu=0 for

Linux Telnet vt100 Return key sends ^M

久未见 提交于 2019-12-06 09:12:23
问题 I'm writing Telnet automation scripts with TCL and Expect in Linux Debian. Pressing Return in a Telnet session or within a *.tcl script ( send "command\r" ) and even send "command\n" causes the line being send with ^M (Ctrl+M) at the end. Off course, the remote host treats those commands as illegal. Tried to telnet set crlf prior to the opening of the connection and mode line while connected, but this has no effect. Using Puttys GUI, I've enabled this option to send a new line by pressing

Export Bash command-line-argument variables for use in embedded Expect

可紊 提交于 2019-12-06 08:08:36
问题 The echo test shows me my command line variables are working, but how do I pass them, export them, to be used in an embedded expect ? #!/bin/bash echo name of script is $0 echo host is $1 echo hostusername is $2 echo hostpassword is $3 expect -c 'spawn ssh -l $2 $1 < ./sf-wall_scp_bash.sh sleep 2 expect { "(yes/no)? " {send "yes\n"} exp_continue } expect { "?assword" {send "$3\r"} } sleep 1 ' If invoked with the expect shebang, it works like #!/usr/bin/expect set host [lindex $argv 0] set

Handle multiple statement in expect script

橙三吉。 提交于 2019-12-06 07:31:56
问题 I am new in expect scripting. I wrote a expect script for ssh in a linux machine,where I am facing problem in sshing on different linux machines.Below I have copied the script. !/usr/local/bin/expect set LinuxMachine [lindex $argv 0] spawn ssh root@$LinuxMachine expect "root@$LinuxMachine's password:" send "root123\n" expect "[root@Client_FC12_172_85 ~]#" send "ls" interact When I supply 10.213.172.85 from command line the expect in the 4th line , it reads as " root@10.213.172.85's password:

Automating xterm using Expect

假装没事ソ 提交于 2019-12-06 07:27:06
I am trying to automate xterm window using Expect (though I already knew Expect cant control such GUI applications, but there is a tweaked mechanism explained in Exploring Expect ) package require Expect spawn -pty stty raw -echo < $spawn_out(slave,name) regexp ".*(.)(.)" $spawn_out(slave,name) dummy c1 c2 if {[string compare $c1 "/"] == 0} { set c1 "0" } set xterm_pid [exec xterm -S$c1$c2$spawn_out(slave,fd) &] close -slave expect "\n" ;# match and discard X window id set xterm $spawn_id spawn $env(SHELL) Don Libes mentioned that from this point, xterm can be automated and he has given

python_unittest参数化

这一生的挚爱 提交于 2019-12-06 05:47:31
unittest参数化 1 import parameterized 2 import unittest,BeautifulReport 3 4 #数据驱动 5 #代码驱动 6 #关键字驱动 7 8 data = [ 9 ['admin','123456',True,'正常登录'], 10 ['admin','21123',False,'密码错误'], 11 ['admin1','123456',False,'用户名错误'] 12 ] 13 14 data1 = [ 15 ['admin','123456',True,'正常登录'], 16 ['admin','21123',False,'密码错误'], 17 ['admin1','123456',False,'用户名错误'] 18 ] 19 20 def login(user,password): 21 if user =='admin' and password == '123456': 22 return True 23 return False 24 25 class LoginTest(unittest.TestCase): 26 @parameterized.parameterized.expand(data) 27 def test_login(self,user,password,expect,desc): 28

Why expect makes process open it's STDERR?

独自空忆成欢 提交于 2019-12-06 05:13:40
I want to set timeout for a process, this is my shell. I use expect to do it, in order to avoid other packages dependencies. test.sh #!/bin/bash # $1 timeout in seconds # $2 command timeout() { time=$1 shift # start the command in a subshell to avoid problem with pipes # (spawn accepts one command) -noecho command="/bin/sh -c \"$*\"" expect -c "set echo \"-noecho\";set timeout $time; spawn -noecho $command; expect timeout { exit 1 } eof { exit 0 }" if [ $? = 1 ] ; then echo "timeout after ${time} seconds" exit 1 fi } timeout 120 ./test test.c #include <stdlib.h> int main() { sleep(120); } And

Error handling in bash/expect script

孤街醉人 提交于 2019-12-06 04:39:21
问题 Pasted below is a bash script, combined with expect code, which: connects to remote host via ssh, collects files and prepare tgz file; copy tgz file from remote host to local machine; connects to remote host via ssh again and remove previously created tgz file; finally, extract tgz file on local machine. Everything works, if passed arguments are valid (i.e., $host , $user , and $pass ). If one of them is incorrect, script hangs. I wonder how to include some error handling (e.g., in $cmd1) to

Use `expect` to scroll through and accept license agreement

為{幸葍}努か 提交于 2019-12-06 02:44:47
问题 I've got a bunch of Macs that have just updated Xcode and need to have the EULA agreement accepted. I'm trying to do this through a script. #!/usr/bin/expect set timeout 15 spawn sudo xcodebuild -license expect { "*License.rtf'\n" { # Press Enter to view agreement send "\r" } timeout { send_user "\nFailed\n"; exit 1 } } expect { "Software License Agreements Press 'space' for more, or 'q' for quit" { send_user " "; exp_continue; } "By typing 'agree' you are agreeing" { send_user "agree\r" }