Hi,
I am trying to shutdown down a Virtual machine by ssh'ing into it via
Tcl/Expect. At the point after I send "yes\r" using the send command in
response to a confirmation request of my earlier shutdown request, sometimes
I find a print out of just "y" and expect times out while waiting for the
follow-on shutdown confirmation.
Can someone help with a solution/workaround asap?
I assume, send was not able to flush out the remaining characters for some
reason to the Linux box. The Tcl/Expect script is on a Linux machine.
Thanks.
|
|
0
|
|
|
|
Reply
|
sogorai (3)
|
2/7/2011 1:01:00 AM |
|
sg332 wrote:
> Hi,
>
> I am trying to shutdown down a Virtual machine by ssh'ing into it via
> Tcl/Expect. At the point after I send "yes\r" using the send command in
> response to a confirmation request of my earlier shutdown request, sometimes
> I find a print out of just "y" and expect times out while waiting for the
> follow-on shutdown confirmation.
>
But does the V-Box shut down as commanded ?
Do you [expect] the confirmation text ?
> Can someone help with a solution/workaround asap?
you may want to expect eof and see what is in the expect buffer ?
>
> I assume, send was not able to flush out the remaining characters for some
> reason to the Linux box. The Tcl/Expect script is on a Linux machine.
You drop back to a shell, right?
send another \r to expect a prompt ( and maybe any output "stuck" without a newline )
>
> Thanks.
>
>
uwe
|
|
0
|
|
|
|
Reply
|
Uwe
|
2/7/2011 9:35:57 AM
|
|
Am 07.02.2011 02:01, schrieb sg332:
> Hi,
>
> I am trying to shutdown down a Virtual machine by ssh'ing into it via
> Tcl/Expect. At the point after I send "yes\r" using the send command in
> response to a confirmation request of my earlier shutdown request, sometimes
> I find a print out of just "y" and expect times out while waiting for the
> follow-on shutdown confirmation.
>
> Can someone help with a solution/workaround asap?
>
> I assume, send was not able to flush out the remaining characters for some
> reason to the Linux box. The Tcl/Expect script is on a Linux machine.
>
> Thanks.
>
>
I use the halt command to shutdown a linux machine. It never
needs any confirmation, no need for expect.
/Str.
|
|
0
|
|
|
|
Reply
|
M
|
2/8/2011 9:07:36 AM
|
|
Hi Uwe,
Thanks for your reply. Sorry for the delay in my reply. Please see inline
for my comments. preceded by [sg332 2011_02_09_00_03]:
It seems like that send "yes\r" is getting stuck with at "y". All other
preceding send commands in the script work fine.
Is there any way to force flush this send buffer?
Thanks.
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:t0r428-9nk.ln1@klein-habertwedt.de...
> sg332 wrote:
>> Hi,
>>
>> I am trying to shutdown down a Virtual machine by ssh'ing into it via
>> Tcl/Expect. At the point after I send "yes\r" using the send command in
>> response to a confirmation request of my earlier shutdown request,
>> sometimes I find a print out of just "y" and expect times out while
>> waiting for the follow-on shutdown confirmation.
>>
> But does the V-Box shut down as commanded ?
sg332 2011_02_09_00_03] No. That probably means send has not sent "yes\r" to
the VM.
>
> Do you [expect] the confirmation text ?
sg332 2011_02_09_00_03] Yes.
>
>> Can someone help with a solution/workaround asap?
>
> you may want to expect eof and see what is in the expect buffer ?
[sg332 2011_02_09_00_03]: Since nothing is sent, expect will timeout.
>>
>> I assume, send was not able to flush out the remaining characters for
>> some reason to the Linux box. The Tcl/Expect script is on a Linux
>> machine.
>
> You drop back to a shell, right?
[sg332 2011_02_09_00_03]: The VM is waiting...and my script will timeout and
exit as I throw an exception..
> send another \r to expect a prompt ( and maybe any output "stuck" without
> a newline )
[sg332 2011_02_09_00_03]: Didn't work.
>>
>> Thanks.
> uwe
|
|
0
|
|
|
|
Reply
|
sg332
|
2/9/2011 8:07:27 AM
|
|
Hi Str,
Thanks for you reply. Thanks for the suggestion on the "halt" command. In my
case, I want to gracefully shutdown the box, which means applications on
that remote machine should shutdown gracefully before the OS starts shutting
down. A OS platform command that I am using allows me to do so. But for
that, I have to ssh into the platform using platform credentials.
Thanks.
"M. Strobel" <sorry_no_mail_here@nowhere.dee> wrote in message
news:8rcfeoF9omU1@mid.uni-berlin.de...
> Am 07.02.2011 02:01, schrieb sg332:
>> Hi,
>>
>> I am trying to shutdown down a Virtual machine by ssh'ing into it via
>> Tcl/Expect. At the point after I send "yes\r" using the send command in
>> response to a confirmation request of my earlier shutdown request,
>> sometimes
>> I find a print out of just "y" and expect times out while waiting for the
>> follow-on shutdown confirmation.
>>
>> Can someone help with a solution/workaround asap?
>>
>> I assume, send was not able to flush out the remaining characters for
>> some
>> reason to the Linux box. The Tcl/Expect script is on a Linux machine.
>>
>> Thanks.
>>
>>
>
> I use the halt command to shutdown a linux machine. It never
> needs any confirmation, no need for expect.
>
> /Str.
|
|
0
|
|
|
|
Reply
|
sg332
|
2/9/2011 8:09:51 AM
|
|
sg332 wrote:
> It seems like that send "yes\r" is getting stuck with at "y". All other
> preceding send commands in the script work fine.
> Is there any way to force flush this send buffer?
Q1: What is the action/expect sequence before you send "yes\r" ?
Q2: If you do this manually is the "yes\r" echoed ?
my interpretation/guess:
could the "y" be the result of switching from "echo mode"
to drain input, switch to "no echo" for user input
while you send the "yes\r" string and this input is
thus partially or completely lost?
( this is an [expect] problem regularly attached to
expecting "not enough" ;-)
i.e. you send before the shutdown command is
ready to listen to user input.
shutdown waits for input
expect waits for input
impasse
>
uwe
|
|
0
|
|
|
|
Reply
|
Uwe
|
2/9/2011 8:37:44 AM
|
|
Hi Uwe,
Please see inline preceded by [sg332_2]
Also, it looks like any character sent will be hanging at that spot in
certain times. That means that expect send is indeed not flushing the
charaters at that time periodically. I know for open command you can use
flush stdout. is there something similar for expect send? then I might be
able to get my problem resolved.
Thanks,
Soumo.
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:ob0a28-kfd.ln1@klein-habertwedt.de...
> sg332 wrote:
>
>> It seems like that send "yes\r" is getting stuck with at "y". All other
>> preceding send commands in the script work fine.
>> Is there any way to force flush this send buffer?
>
> Q1: What is the action/expect sequence before you send "yes\r" ?
[sg332_2]: I get "admin:" I send system shutdown command. I get "Do you
really want to shutdown?" followed by "Enter (yes/no)?" and then I send
"yes\r". Below is what it looks like on the terminal
admin:8: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: got
admin prompt...
9: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: sent shutdown
command.
utils system shutdown
Do you really want to shutdown ?
Enter (yes/no)? 10: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG:
stopNodeGracefully: got confirm shutdown...
11: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: sent
shutdown confirmation.
y
> Q2: If you do this manually is the "yes\r" echoed ?
[sg332_2]: No. How do I disable the console echo? stty -echo didn't work
>
>
> my interpretation/guess:
> could the "y" be the result of switching from "echo mode"
> to drain input, switch to "no echo" for user input
> while you send the "yes\r" string and this input is
> thus partially or completely lost?
[sg332_2]: How do I disable the console echo? stty -echo didn't work
> ( this is an [expect] problem regularly attached to
> expecting "not enough" ;-)
[sg332_2]: is there no workaround?
>
> i.e. you send before the shutdown command is
> ready to listen to user input.
>
> shutdown waits for input
> expect waits for input
> impasse
>>
> uwe
|
|
0
|
|
|
|
Reply
|
sg332
|
2/11/2011 9:46:08 AM
|
|
sg332 wrote:
> Hi Uwe,
> Please see inline preceded by [sg332_2]
>
> Also, it looks like any character sent will be hanging at that spot in
> certain times. That means that expect send is indeed not flushing the
> charaters at that time periodically. I know for open command you can use
> flush stdout. is there something similar for expect send? then I might be
> able to get my problem resolved.
>
> Thanks,
> Soumo.
>
>
> "Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
> news:ob0a28-kfd.ln1@klein-habertwedt.de...
>
>>sg332 wrote:
>>
>>
>>>It seems like that send "yes\r" is getting stuck with at "y". All other
>>>preceding send commands in the script work fine.
>>>Is there any way to force flush this send buffer?
>>
>>Q1: What is the action/expect sequence before you send "yes\r" ?
>
> [sg332_2]: I get "admin:" I send system shutdown command. I get "Do you
> really want to shutdown?" followed by "Enter (yes/no)?" and then I send
> "yes\r". Below is what it looks like on the terminal
>
> admin:8: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: got
> admin prompt...
> 9: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: sent shutdown
> command.
> utils system shutdown
>
> Do you really want to shutdown ?
>
> Enter (yes/no)? 10: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG:
-----------------^ see that space after the '?' ( "10..." is from your debug output, right?
please change your expect script to expect the full ..yes/no.. pattern
i.e.
expect ... \
"(yes/no)? " {
puts stderr "Y/N seen"
exp_send "yes\r"
} eof {
puts stderr EOF
} timeout {
puts stderr TIMEOUT
}
> stopNodeGracefully: got confirm shutdown...
> 11: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: sent
> shutdown confirmation.
> y
>
>
>
>>Q2: If you do this manually is the "yes\r" echoed ?
>
> [sg332_2]: No. How do I disable the console echo? stty -echo didn't work
You don't need to.
I was asking to have an idea about the action sequence on the shutdown programm side.
>
>>
>>my interpretation/guess:
>>could the "y" be the result of switching from "echo mode"
>>to drain input, switch to "no echo" for user input
>>while you send the "yes\r" string and this input is
>>thus partially or completely lost?
looks like my diagnosis is correct.
>
> [sg332_2]: How do I disable the console echo? stty -echo didn't work
you don't want to.
>
>
>>( this is an [expect] problem regularly attached to
>>expecting "not enough" ;-)
>
> [sg332_2]: is there no workaround?
sure, expect more ;-) see above.
>
>
>>i.e. you send before the shutdown command is
>>ready to listen to user input.
>>
>>shutdown waits for input
>>expect waits for input
>>impasse
>>
uwe
|
|
0
|
|
|
|
Reply
|
Uwe
|
2/11/2011 10:20:22 AM
|
|
Hi Uwe,
I tried adding the space as you mentioned so that my expect pattern is
"Enter (yes/no) ?: " (with a space after ?). but still no luck same output
with "y" and hanging and then timeout on the subsequent expect. I tried
expanding the pattern to include the prior shutdown question. "Do you really
want to shutdown?\n\nEnter (yes/no) ?: " but this time expect doesn't even
recognize the pattern. Is the string correct? I didn't see any space after
shutdown
Thanks.
So code looks like this:
//before the following code: I expect "admin:" and send shutdown command.
expect {
-i $sshSpawnId
"Enter (yes/no)? " {
::test::log -level debug -msg "[thisProcName]: got confirm shutdown..."
send -i $sshSpawnId "yes\r"
::test::log -level debug -msg "[thisProcName]: sent shutdown confirmation."
}
timeout {
::test::log -msg "[thisProcName]: timed out. didn't get confirm shutdown
prompt"
if {[info exists expect_out(buffer)]} {
::test::log -msg "%s" "[thisProcName]: buffer: $expect_out(buffer)."
}
set resultCode [catch {close -i $sshSpawnId} errorMsg];
::nasc::handleCloseProcess $resultCode $errorMsg $sshSpawnId
set waitCode [catch {wait -nowait -i $sshSpawnId} waitMsg]
::nasc::handleWaitProcess $waitCode $waitMsg $sshSpawnId
::test::throw_error -name ExpectError -msg "timed out. didn't get confirm
shutdown prompt"
}
eof {
::test::log -msg "[thisProcName]: eof. didn't get confirm shutdown prompt"
if {[info exists expect_out(buffer)]} {
::test::log -msg "%s" "[thisProcName]: buffer: $expect_out(buffer)."
}
set resultCode [catch {close -i $sshSpawnId} errorMsg];
::nasc::handleCloseProcess $resultCode $errorMsg $sshSpawnId
set waitCode [catch {wait -nowait -i $sshSpawnId} waitMsg]
::nasc::handleWaitProcess $waitCode $waitMsg $sshSpawnId
::test::throw_error -name ExpectError -msg "eof. didn't get confirm shutdown
prompt"
}
};
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:74ff28-ig6.ln1@klein-habertwedt.de...
> sg332 wrote:
>> Hi Uwe,
>> Please see inline preceded by [sg332_2]
>>
>> Also, it looks like any character sent will be hanging at that spot in
>> certain times. That means that expect send is indeed not flushing the
>> charaters at that time periodically. I know for open command you can use
>> flush stdout. is there something similar for expect send? then I might be
>> able to get my problem resolved.
>>
>> Thanks,
>> Soumo.
>>
>>
>> "Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
>> news:ob0a28-kfd.ln1@klein-habertwedt.de...
>>
>>>sg332 wrote:
>>>
>>>
>>>>It seems like that send "yes\r" is getting stuck with at "y". All other
>>>>preceding send commands in the script work fine.
>>>>Is there any way to force flush this send buffer?
>>>
>>>Q1: What is the action/expect sequence before you send "yes\r" ?
>>
>> [sg332_2]: I get "admin:" I send system shutdown command. I get "Do you
>> really want to shutdown?" followed by "Enter (yes/no)?" and then I send
>> "yes\r". Below is what it looks like on the terminal
>>
>> admin:8: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: got
>> admin prompt...
>> 9: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: sent
>> shutdown command.
>> utils system shutdown
>>
>> Do you really want to shutdown ?
>>
>> Enter (yes/no)? 10: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG:
> -----------------^ see that space after the '?' ( "10..." is from your
> debug output, right?
>
> please change your expect script to expect the full ..yes/no.. pattern
>
> i.e.
>
> expect ... \
> "(yes/no)? " {
> puts stderr "Y/N seen"
> exp_send "yes\r"
> } eof {
> puts stderr EOF
> } timeout {
> puts stderr TIMEOUT
> }
>
>
>> stopNodeGracefully: got confirm shutdown...
>> 11: : 2011-02-11T01:28:07: %SCRIPT-7-DEBUG: stopNodeGracefully: sent
>> shutdown confirmation.
>> y
>>
>>
>>
>>>Q2: If you do this manually is the "yes\r" echoed ?
>>
>> [sg332_2]: No. How do I disable the console echo? stty -echo didn't work
> You don't need to.
> I was asking to have an idea about the action sequence on the shutdown
> programm side.
>
>>
>>>
>>>my interpretation/guess:
>>>could the "y" be the result of switching from "echo mode"
>>>to drain input, switch to "no echo" for user input
>>>while you send the "yes\r" string and this input is
>>>thus partially or completely lost?
> looks like my diagnosis is correct.
>
>>
>> [sg332_2]: How do I disable the console echo? stty -echo didn't work
> you don't want to.
>>
>>
>>>( this is an [expect] problem regularly attached to
>>>expecting "not enough" ;-)
>>
>> [sg332_2]: is there no workaround?
> sure, expect more ;-) see above.
>>
>>
>>>i.e. you send before the shutdown command is
>>>ready to listen to user input.
>>>
>>>shutdown waits for input
>>>expect waits for input
>>>impasse
>>>
> uwe
>
|
|
0
|
|
|
|
Reply
|
sg332
|
2/11/2011 7:54:23 PM
|
|
Am 09.02.2011 09:09, schrieb sg332:
> Hi Str,
>
> Thanks for you reply. Thanks for the suggestion on the "halt" command. In my
> case, I want to gracefully shutdown the box, which means applications on
> that remote machine should shutdown gracefully before the OS starts shutting
> down. A OS platform command that I am using allows me to do so. But for
> that, I have to ssh into the platform using platform credentials.
>
> Thanks.
>
> "M. Strobel" <sorry_no_mail_here@nowhere.dee> wrote in message
> news:8rcfeoF9omU1@mid.uni-berlin.de...
>> Am 07.02.2011 02:01, schrieb sg332:
>>> Hi,
>>>
>>> I am trying to shutdown down a Virtual machine by ssh'ing into it via
>>> Tcl/Expect. At the point after I send "yes\r" using the send command in
>>> response to a confirmation request of my earlier shutdown request,
>>> sometimes
....
>>>
>>> Thanks.
>>>
>>>
>>
>> I use the halt command to shutdown a linux machine. It never
>> needs any confirmation, no need for expect.
>>
>> /Str.
>
I think every halt is graceful, it is not forced and leaves the
system in a consistent state.
And halt calls shutdown, see the man page.
If you want to be extremely graceful, you need a more elaborate
script, taking care for example to call the apache2-script with
'graceful' (this depends on your distro, see apache2ctl).
And are you aware that you can call any command directly after
ssh? Test this:
ssh user@example.com uptime
And of course, public key authetication.
/Str.
|
|
0
|
|
|
|
Reply
|
sorry_no_mail_here (506)
|
2/13/2011 12:01:48 PM
|
|
Hi Str,
Thanks for your reply. Correct me if I am wrong but I believe shutdown
(indirectly can be invoked by halt) will "kill" all the processes running on
top of the OS. But what I would like to do is allow the applications running
on top of the OS to be able to detect shutdown and gracefully come to a
halt. I am actually shutting down a VOS (which is an OS built from Linux)
machine and my script calls a VOS command that allows the applications to
gracefully shutdown.
Thanks.
"M. Strobel" <sorry_no_mail_here@nowhere.dee> wrote in message
news:8rpvhcFitgU1@mid.uni-berlin.de...
> Am 09.02.2011 09:09, schrieb sg332:
>> Hi Str,
>>
>> Thanks for you reply. Thanks for the suggestion on the "halt" command. In
>> my
>> case, I want to gracefully shutdown the box, which means applications on
>> that remote machine should shutdown gracefully before the OS starts
>> shutting
>> down. A OS platform command that I am using allows me to do so. But for
>> that, I have to ssh into the platform using platform credentials.
>>
>> Thanks.
>>
>> "M. Strobel" <sorry_no_mail_here@nowhere.dee> wrote in message
>> news:8rcfeoF9omU1@mid.uni-berlin.de...
>>> Am 07.02.2011 02:01, schrieb sg332:
>>>> Hi,
>>>>
>>>> I am trying to shutdown down a Virtual machine by ssh'ing into it via
>>>> Tcl/Expect. At the point after I send "yes\r" using the send command in
>>>> response to a confirmation request of my earlier shutdown request,
>>>> sometimes
> ...
>>>>
>>>> Thanks.
>>>>
>>>>
>>>
>>> I use the halt command to shutdown a linux machine. It never
>>> needs any confirmation, no need for expect.
>>>
>>> /Str.
>>
>
> I think every halt is graceful, it is not forced and leaves the
> system in a consistent state.
>
> And halt calls shutdown, see the man page.
>
> If you want to be extremely graceful, you need a more elaborate
> script, taking care for example to call the apache2-script with
> 'graceful' (this depends on your distro, see apache2ctl).
>
> And are you aware that you can call any command directly after
> ssh? Test this:
> ssh user@example.com uptime
>
> And of course, public key authetication.
>
> /Str.
|
|
0
|
|
|
|
Reply
|
sogorai (3)
|
2/13/2011 6:47:35 PM
|
|
On Feb 13, 6:01=A0am, "M. Strobel" <sorry_no_mail_h...@nowhere.dee>
wrote:
> Am 09.02.2011 09:09, schrieb sg332:
>
>
>
>
>
>
>
>
>
> > Hi Str,
>
> > Thanks for you reply. Thanks for the suggestion on the "halt" command. =
In my
> > case, I want to gracefully shutdown the box, which means applications o=
n
> > that remote machine should shutdown gracefully before the OS starts shu=
tting
> > down. A OS platform command that I am using allows me to do so. But for
> > that, I have to ssh into the platform using platform credentials.
>
> > Thanks.
>
> > "M. Strobel" <sorry_no_mail_h...@nowhere.dee> wrote in message
> >news:8rcfeoF9omU1@mid.uni-berlin.de...
> >> Am 07.02.2011 02:01, schrieb sg332:
> >>> Hi,
>
> >>> I am trying to shutdown down a Virtual machine by ssh'ing into it via
> >>> Tcl/Expect. At the point after I send "yes\r" using the send command =
in
> >>> response to a confirmation request of my earlier shutdown request,
> >>> sometimes
> ...
>
> >>> Thanks.
>
> >> I use the halt command to shutdown a linux machine. It never
> >> needs any confirmation, no need for expect.
>
> >> /Str.
>
> I think every halt is graceful, it is not forced and leaves the
> system in a consistent state.
>
> And halt calls shutdown, see the man page.
>
> If you want to be extremely graceful, you need a more elaborate
> script, taking care for example to call the apache2-script with
> 'graceful' (this depends on your distro, see apache2ctl).
>
> And are you aware that you can call any command directly after
> ssh? Test this:
> =A0 =A0 =A0 =A0 ssh u...@example.com uptime
>
> And of course, public key authetication.
>
> /Str.
Don't need to set up keys ahead of time if you also use expect to
negotiate the ssh login. You would just have to get the password
everytime ( or store it ). But the work around is to exchange the keys
the first time so that password is only used once.
Carl
|
|
0
|
|
|
|
Reply
|
cwjolly (224)
|
2/14/2011 6:38:54 PM
|
|
|
11 Replies
420 Views
(page loaded in 0.425 seconds)
|