I am writing an Expect Script to execute some commands over ssh then exit the script.
The script works just fine if I automate everything and assuming the correct password was entered.
So this Expect Script gets executed from a Bash script... From the Bash script I pass along an IP Address,
then "I" prompt them for a Username and a Password from within the Bash script, then pass it along to the
Expect Script as arguments. If the password entered is correct, the script runs smoothly without any problems.
But I was trying to add a section in the script that, if the password is incorrect, then I wanted to issue the
"interact" command and have the user try again until either they get the password correct or until they surpass
the amount of allowed retries.
I was trying to accomplish this with a while loop but couldn't seem to get it working correctly.
Here's what I've tried so far:This example doesn't have the while loop...
So like I was saying, this one works just fine when the password is correct. But when the password is NOT correct
and I pass control to the user, after he enters the password and hits "Enter", control stays with the user and
never goes back to the script.
Is there something wrong I am doing with the "interact" command..?
This code below here I had right inside the first "expect { }" section that continas the "*assword:" and the "timeout".
I tried doing this a bunch of different ways with the while loop, but I can't seem to get it working correctly.
If anyone has any suggestions at all of what is a good way that I can accomplish this, PLEASE feel free. I am stumped
** Basically if the first password that is entered by the user, and passed to the Expect Script is incorrect I want to
pass control to the user to try another password. Then, after the user types the password and hits "Enter" pass
control back to Expect... and do this until we find a normal command prompt (which signifies a correct password was
entered)... Or until the maximum retries has been reached.
Thanks in Advance,
Matt
---------- Post updated at 04:03 PM ---------- Previous update was at 03:09 PM ----------
Humm... I think I was getting a little overwhelmed so I started over from scratch, and now it seems to be working...?
Not sure what was different in this interact command compared to the one in my OP...
Here's what seems to be working:
But I would still like to try getting a while loop in there for this if anyone could at least show me how it should be formatted...
And what would the best way to break outta the loop.
Hi All,
i am trying to ssh to a remote machine and execute certain command to remote machine through script.
i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as
expect: spawn id exp5 not open
while executing
"expect "$" {... (3 Replies)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
hi
i want to automate fdisk command .
i spawned a process containing fdisk command from a process
and tried to send the options to fdisk promt from that process.
but that spawed process is notstarting itself
help me out
trying for two days
:wall:
my code:
#!/bin/bash
echo... (5 Replies)
I am trying to match a text which contains the " ", from the log file. But it doesn't match. I understand that " " has got a special meaning to TCL/Expect.
hence I tried the following, but no luck.
expect -ex {
"lp -c -demail -ot\\\"firstname_surname@gmail.com\\\"... (3 Replies)
I'm trying to execute something like this:
exec perl -i -pe 's/\015/\012/g' '${file}'
in my expect script and I get:
error "invalid command name \"perl\".
however, if I run
perl -i -pe 's/\015/\012/g' "/Users/Shared/menu-items.txt"
directly in my terminal, it runs fine. I'm an... (4 Replies)
I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this:
$ look "string" "/home/patrick/filename.txt"
However, this gives me the following message:
"look: /home/patrick/filename.txt: File too large"
So, I have two... (14 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
So, I have an expect script (let's call it expect.exp) that takes 3 arguments. It logs into a remote server, runs a set of commands, then hands control over to the user by the "interact" command. If I call this script from the command line, it works properly.
Now I'd like to apply this script... (2 Replies)
I wrote some expect script to telnet to some device to execute some commands.Firstly,I can't get full result some time,then I try to add some "sleep" command in it.Fortunately it works.
My idea about it is that it uses sleep command to wait the result to be displayed.Am I right or correct the... (4 Replies)
Hi,
Iam using Solaris 10 OS in the server.iam unable to find expect command in bin directory.how can i install the script in the server to use "expect" in shell programming. (1 Reply)