expect

Expect script to find file existence on remote server

允我心安 提交于 2019-12-11 09:17:13
问题 I am writing an expect script to figure out the existence of a specific file on a remote server. My test server is located in the same network as the remote server. While I tried to search through stackoverflow for similar stuff all I could find is expect scripts that would work on local server. This link (How to find if a file exists in expect script) was the closest. On similar lines I found the following website to - Expect with SFTP Expect Script Based on both I tried to write my expect

Expect script not able to read mkdir from file and execute

大憨熊 提交于 2019-12-11 08:27:55
问题 This is a continuation of this topic; since it's a different question from the OP I'm making a new topic. I have an expect script I can't get working that is supposed to read commands from a file and execute them. This is the script itself, called script.sh : #!/usr/bin/expect set prompt {\$\s*$} set f [open "script_cmds_u.txt"] set cmds [split [read $f] "\n"] close $f foreach cmd $cmds { spawn $cmd expect -re $prompt } expect eof close The file script_cmds.txt looks like this: mkdir

Can expect scripts read data from stdin?

99封情书 提交于 2019-12-11 07:37:17
问题 When executing expect scripts, arguments are visible on ps ax which can be a security vulnerability if they are sensitive. Trying to automate opening a tab on iTerm2, running ssh admin@host and entering the passphrase when asked Enter passphrase for key '/Users/admin/.ssh/key' (the key is encrypted using that passphrase). Host host HostName 1.2.3.4 IdentityFile ~/.ssh/key I would like to supply the passphrase to bash using read -sp 'Passphrase: ' passphrase and then pipe it to expect (which

How to run Unix shell script in a java code using ExpectJ tool?

旧城冷巷雨未停 提交于 2019-12-11 06:52:22
问题 This is my hello.sh shell script VALID_NAME="abcd" echo "Name: " read name if [ "$name" == $VALID_NAME ]; then echo "correct" else echo "unexpected input" fi ======================================================== This is my Java code import java.io.IOException; import expectj.*; public class Trial { public static void main(String[] args) { ExpectJ exp = new ExpectJ(); String command = "sh /root/Desktop/hello.sh"; Spawn s; try { s = exp.spawn(command); s.expect("Name: "); s.send("abcd");

Using procedure for spawing SSH doesn't work properly with expect

只谈情不闲聊 提交于 2019-12-11 05:47:55
问题 I have a expect script which when uses a procedure to spawn SSH and, later using expect doesn't work, when ssh spawn is directly used, the expect thing seems to work fine. Any idea what can be wrong here ?? I am using the same code snippet in the other case and works fine. proc sshLogin {serverName userName password} { global logfd set timeout 10 logMessage "Connecting to server = $serverName, please wait..." log_user 0 spawn -noecho ssh -X "$userName\@$serverName" expect { "password:" { send

can expect be told not to timeout without explicitly setting a huge constant value?

风格不统一 提交于 2019-12-11 05:46:43
问题 I've set the timeout to a stupid high number. Is there a better way to tell the script not to time out? #!/usr/bin/expect spawn telnet 10.10.10.10 set timeout 200000000 expect "login" send "user\r" expect "Password:" send "password\r" send "./run/this.sh\r" 回答1: Set the timeout value to -1 set timeout -1 An excerpt from the expect , man page If no timeout keyword is used, an implicit null action is executed upon timeout. The default timeout period is 10 seconds but may be set, for example to

Questions on Regex algorithm (not necessarily EXPECT related)

会有一股神秘感。 提交于 2019-12-11 05:15:21
问题 I'm trying to create a regex to capture the neighbor detail of my devices (example output below). I could hard code each individual line, but I'm looking for a better solution. maybe learn a new algorithm. I'm interested in capturing Device ID (HOST1), Interface (GigabitEthernet0/1), and Port ID (GigabitEthernet2/43). for each neighbor and store it in a list comma separated. send "show cdp neighbors detail\r" expect { -re "-+\r\nDevice ID: (\[^\r]+)\r\n\[^\r]+\r\n\[^\r]+\r\n\[^\r]+\r

TCL\Expect:: Script that is running on Windows XP is not running on Windows 7. Any ideas please?

北城以北 提交于 2019-12-11 04:48:11
问题 Following is my TCL/Expect Script: package require Expect spawn telnet 2.2.2.10 expect "*ogin:" send "admin\r" expect "*word:" send "test\r" expect "*>" send "enable\r" expect "*#" The above script runs in "Windows XP" machine. But when I run this same script in "Windows 7", its throws following error: C:\Users\test\Desktop>tclsh 3_AP_collect_sign.tcl The system cannot find the file specified. while executing "spawn telnet 2.2.2.10" (file "3_AP_collect_sign.tcl" line 6) C:\Users\Symbol

Expecting the Unexpected in Expect

a 夏天 提交于 2019-12-11 04:43:29
问题 How can I give an instruction to expect, when it sees anything other than what it expects? Example, I attempt to automate a login. For anything other than a successful attempt, I need the script to mail me an error. How do I expect unexpected output? (I know some outcomes, like connection denied, or wrong password, but I want to catch everything) 回答1: Try like this: set timeout 10; # set a reasonable timeout # expect and send username/password ... set success 0 set err_msg "" expect { "Login

Get the output of a command executed via $self->send() on a remote host in Perl Expect module

别等时光非礼了梦想. 提交于 2019-12-11 04:12:42
问题 I am using Expect module in Perl to do an interactive activity and execute a command on a remote machine. Request your help on this Here are the steps I used Do a switch user to another account. Sends the password to login. Once I get the shell for the new user, execute a ssh command to connect to a remote machine. Then I want to execute a command in that remote machine and get its response. I am able to execute the command on the remote machine. I am seeing the output on my terminal too. But