From: hadi motamedi on
> If issuing the commands manually produces the desired output, you
> could try autoexpect¹ and edit the output of running an autoexpect
> session to your liking. There is a manual page too².
>
> Thank you very much for your help . This is very near to what I really want
to do . I tried as the followings :
#autoexpect -c

#telnet 172.16.17.160
->command1
->logout
#exit
It has produced an script named 'script.exp' . When I run this script , I
see automatic telnet to the VxWorks remote node and then issuing the desired
command but to exit I need to press Ctrl-C . Then I tried to automate it
like the following :

#for i in 1 2 3 4 5
>do
>./script.exp
>sleep 10
>done
It is quite ok , except for the need that I must press Ctrl-C at the end of
every run . Can you please let me know how to remove that un-necessary
hitting of Ctrl-C ?
From: d.sastre.medina on
On Thu, May 06, 2010 at 08:48:48AM +0100, hadi motamedi wrote:
> I tried as the followings :
> #autoexpect -c
>
> #telnet 172.16.17.160
> ->command1
> ->logout
> #exit
> It has produced an script named 'script.exp' . When I run this script , I
> see automatic telnet to the VxWorks remote node and then issuing the desired
> command but to exit I need to press Ctrl-C . Then I tried to automate it
> like the following :
>
> #for i in 1 2 3 4 5
> >do
> >./script.exp
> >sleep 10
> >done
> It is quite ok , except for the need that I must press Ctrl-C at the end of
> every run . Can you please let me know how to remove that un-necessary
> hitting of Ctrl-C ?

When exactly you need to press Control-C? After exiting the remote
node? Before? I'd really need to look at the script you are using, the
one produced by the autoexpect session, but you could try either sending
an extra `exit' string or sending a control-C (send \003)
Take a look here¹ for more ASCII Control Characters.

Regarding the second part, the way you automate the task can't be
really called _scheduling_, (i.e., a script will be executed every
Sunday at 13:00). That is _iteration_, your script will be executed
five times in a row. But I think you know better than me what you want to
accomplish with it.

Regards.

¹http://en.wikipedia.org/wiki/ASCII

--
Huella de clave primaria: 0FDA C36F F110 54F4 D42B D0EB 617D 396C 448B 31EB
From: Kevin Ross on
On 5/7/2010 11:10 PM, hadi motamedi wrote:
>
>
> node? Before? I'd really need to look at the script you are using, the
> one produced by the autoexpect session, but you could try either
> sending
> an extra `exit' string or sending a control-C (send \003)
> Take a look here� for more ASCII Control Characters.
> When exactly you need to press Control-C? After exiting the remote
>
> Thank you for your reply. Actually, I need to press Ctrl-C after each
> iteration value of 'i' in the 'for i in' loop. Please find attached
> the 'script.exp' that my autoexpect has created. I tried for your
> proposed procedure to send extra 'exit' or 'send \003' in the
> 'script.exp' but it didn't solve the problem. Please help me to
> correct it.
>

Well I see the problem. The autogenerated expect script is waiting for
the exact output of ShowStats that it had the first time you ran
autoexpect, which I assume will be different every time, not the same.

So, change the part that says:

expect --exact "ShowStats\r ...blah blah lots of stats ... BSC1_1_1-> "

to just:

expect "BSC1_1_1-> "


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4BE59D73.6090802(a)familyross.net
From: hadi motamedi on
> Well I see the problem. The autogenerated expect script is waiting for
> the exact output of ShowStats that it had the first time you ran
> autoexpect, which I assume will be different every time, not the same.
> expect --exact "ShowStats\r ...blah blah lots of stats ... BSC1_1_1-> "
> expect "BSC1_1_1-> "
Thank you very much for your reply. You are right and the stats will
be changing for every command run. I modified my script , as attached,
according to your comment but it still needs manually issuing Ctrl-C
at end. Can you please do me favor and correct me for my mistakes?
From: d.sastre.medina on
On Sun, May 09, 2010 at 12:04:58AM -0700, hadi motamedi wrote:
> I modified my script , as attached,
> according to your comment but it still needs manually issuing Ctrl-C
> at end.

Is your script always launched from tmp?
That is what you _exactly expect_:

send -- "logout\r"
expect -exact "
Connection closed by foreign host.\r\r
\[root(a)gprs tmp\]# " <------------------------------------
send -- "exit\r"
expect eof

If that's not the case, you should modify it accordingly.
Please read the comments generated by autoexpect regarding timing and
differing output. Try setting force_conservative to 1 and/or use
regexp in the expected patterns. Try the simplest expect script, i.e, one
that only logs in and logs out.
In your initial post, you said you needed to store the output
somewhere, have you tried log_file?

You don't mention a single trial-error on your side.
Be warned that this community enjoys helping those who help themselves
first. It's been suggested to try a tool and a manpage. I know expect
looks weird at first, so autoexpect was suggested to ease the curve.
But don't expect to be said exactly what to do (pun).

Regards.

--
Huella de clave primaria: 0FDA C36F F110 54F4 D42B D0EB 617D 396C 448B 31EB