I'm using expect to log into a remote host and then execute another script. A log of the script is being created but I can't see to get the script to display while it's running. Any ideas would be appreciated. Here is the script.
I am rather new to using expect and have only written a few scripts using it. I am trying to create a script that will read a file containing a number of hostnames and then for each one: ssh into the box, run a command, scp the output back to a center server.
So far I can make all that... (2 Replies)
I am trying to write a script that telnets out to multiple ip's, runs some commands exits and the telnets to the next ip. I wrote the following script and it works great until the program hits a nonresponsive ip.
I would like this to recognize the ip is bad and move on in the foreach loop. How... (4 Replies)
I am using Expect to spawn a command that loops through a text file and runs the same command for each item in the text file.
The text file, named stat.txt looks something like this:
2007-04 alist 543
2008-07 blist 543
2008-03 xlist 345
2008-03 ylist 675
2003-03 zlist 567
The expect... (1 Reply)
Hi all,
I have got a small expect script like this one.
#!/usr/bin/expect -f
set timeout 2
spawn ftp $env(IP)
match_max 100000
expect -exact "Name"
send -- "$env(USER)\n"
expect -exact "Password:"
send -- "$env(PASSWORD)\n"
expect "%"
send "bin\r"
expect "%"
send "prompt\r"... (5 Replies)
Hi experts,
I have two question about expect script
questions 1
send "tar -xjvf a.tar\r"
send "ifconfig\r"
I want to know if it just run "ifconfig after "tar -xjvf a.tar complete. or the two cmd run at the same time
question 2
after I use the expect to ssh to the... (1 Reply)
I'm having some difficulty with convincing Expect to do what I need..
I have a loop that waits for input, a specific phrase of text followed by a single word. I need Expect to capture that word following the specific phrase. It should then store the word in a variable.
I'm fairly sure it's... (6 Replies)
Hi.,
I need to ask question for expect script.
I have prompt like #
and very long script (orachk).
I added to expect script line
set prompt "(%|#|\\\$) $"
and insert into it also piece of code
----
expect {
timeout {
puts "Running..."
exp_continue
}
... (0 Replies)
I have an expect script that appears to be working normally however for some reason, the remote side appears to be stripping off the variables from the awk command.
This is the original:
expect \"~]$\"
send \"sed 's/=/ /g;s/,/ /g' /home/file.txt | grep abc | awk '{print $6,$8}'This is the... (5 Replies)
Have an expect script but can't seem to de-bug it. It's stalling at the password prompt. If anyone can see a mistake, kindly let me know. Thanks.
Here is the error:
spawn ssh -o StrictHostKeyChecking=no user@xx.xx.xx.xx rpm -qa
# Warning! You have entered into a secured area! #
# All... (2 Replies)
Discussion started by: jimmyf
2 Replies
LEARN ABOUT PHP
expect_expectl
EXPECT_EXPECTL(3) 1 EXPECT_EXPECTL(3)expect_expectl - Waits until the output from a process matches one of the patterns, a specified time period has passed, or anEOFis seenSYNOPSIS
int expect_expectl (resource $expect, array $cases, [array &$match])
DESCRIPTION
Waits until the output from a process matches one of the patterns, a specified time period has passed, or an EOF is seen.
If $match is provided, then it is filled with the result of search. The matched string can be found in $match[0]. The match substrings
(according to the parentheses) in the original pattern can be found in $match[1], $match[2], and so on, up to $match[9] (the limitation of
libexpect).
PARAMETERS
o $expect
- An Expect stream, previously opened with expect_popen(3).
o $cases
- An array of expect cases. Each expect case is an indexed array, as described in the following table:
Expect Case Array
+----------+--------------------------+---+---+---+
|Index Key | | | | |
| | | | | |
| | Value Type | | | |
| | | | | |
| | Description | | | |
| | | | | |
| | Is Mandatory | | | |
| | | | | |
| | Default Value | | | |
| | | | | |
+----------+--------------------------+---+---+---+
| 0 | | | | |
| | | | | |
| | string | | | |
| | | | | |
| | pattern, that will be | | | |
| | matched against the out- | | | |
| | put from the stream | | | |
| | | | | |
| | yes | | | |
| | | | | |
| | | | | |
| | T{ 1 | | | |
| | | | | |
| | mixed | | | |
| | | | | |
| | value, that will be | | | |
| | returned by this func- | | | |
| | tion, if the pattern | | | |
| | matches | | | |
| | | | | |
| | yes | | | |
| | | | | |
| | | | | |
| | T{ 2 | | | |
| | | | | |
| | integer | | | |
| | | | | |
| | pattern type, one of: | | | |
| | EXP_GLOB, EXP_EXACT or | | | |
| | EXP_REGEXP | | | |
| | | | | |
| | no | | | |
| | | | | |
| | | | | |
| | EXP_GLOB | | | |
| | | | | |
+----------+--------------------------+---+---+---+
RETURN VALUES
Returns value associated with the pattern that was matched.
On failure this function returns: EXP_EOF, EXP_TIMEOUT or EXP_FULLBUFFER
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 0.2.1 | |
| | |
| | Prior to version 0.2.1, in $match parameter a |
| | match string was returned, not an array of match |
| | substrings. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
expect_expectl(3) example
<?php
// Copies file from remote host:
ini_set("expect.timeout", 30);
$stream = fopen("expect://scp user@remotehost:/var/log/messages /home/user/messages.txt", "r");
$cases = array(
// array(pattern, value to return if pattern matched)
array("password:", "asked for password"),
array("yes/no)?", "asked for yes/no")
);
while (true) {
switch (expect_expectl($stream, $cases)) {
case "asked for password":
fwrite($stream, "my password
");
break;
case "asked for yes/no":
fwrite($stream, "yes
");
break;
case EXP_TIMEOUT:
case EXP_EOF:
break 2; // break both the switch statement and the while loop
default:
die "Error has occurred!";
}
}
fclose($stream);
?>
SEE ALSO expect_popen(3).
PHP Documentation Group EXPECT_EXPECTL(3)