zsh-workers
 help / color / mirror / code / Atom feed
From: Jaime Vargas <jev@mac.com>
To: Jaime Vargas <jev@mac.com>
Cc: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: zpty woes (enhancement request)
Date: Tue, 20 May 2008 10:28:33 -0400	[thread overview]
Message-ID: <5BA613C5-8227-4803-AFD1-EA2AF754DB20@mac.com> (raw)
In-Reply-To: <BD6F35ED-1F18-4AF7-8A06-1FA46BD4A91A@mac.com>

It would be nice if zpty had a call to inspect the pseudo-terminal  
buffer. I find that `zpty -r' with or without pattern to be very  
difficult to debug. Any ideas on below problem?

On May 19, 2008, at 11:25 PM, Jaime Vargas wrote:

> More strange behavior. In the script below, two different functions  
> doTask and doShellTask are required because when invoking a shell  
> script the prompt is repeated and if a read is not done twice then  
> `zpty -d ch' will kill the session. This is kind of weird, the same  
> happens with the `pwd' command.
>
> Is there a way to avoid this "double prompt" problem? (It is kind  
> of hard which commands would require double reads.)
>
> #!/opt/csw/bin/zsh
>
> # FLAGS
> set -x                                           # Turn on to debug
> zmodload zsh/zpty
>
> # HELPERS
> die () {print -r -- $1 >&2; exit 1;}
>
> doTask () {
>     zpty -w ch $1
>     zpty -t ch || die "Error: command $1 didn't return"
>     zpty -r ch line "*aoma6000-4-9? "
>     print $line
> }
>
> doShellTask () {
>     zpty -w ch $1
>     zpty -t ch || die "Error: command $1 didn't return"
>     zpty -r ch line "*aoma6000-4-9? "
>     zpty -r ch line "*aoma6000-4-9? "
>     print $line
> }
>
>
> # CREDENTIALS
> user='user'
> pass='topsecret'
> supw='topsecret'
> host='host'
>
> # TASKS
> task1='cat >test <<"EOF"
>     #!/bin/zsh
>     who -r
>     uname -a
>     echo hello >test2.out
> EOF
> chmod +x test
> '
>
> # CONNECT
> zpty -b ch ssh -l ${user} ${host}
> zpty -t ch || die "connection failed"
> zpty -r ch line "*assword:" || die "no password asked"
> zpty -w ch ${pass}
> zpty -r ch line "*aoma6000-4-9? "; print $line
>
> doTask 'ls -ltr'
> doTask ${task1}
> doShellTask './test >test.out'
> doShellTask 'pwd'
>
> # DISCONNECT
> zpty -d ch
>
>
> On May 15, 2008, at 1:53 PM, Jaime Vargas wrote:
>
>> I got it working. By changing the pattern to '*assword:'. Thanks  
>> for the help. -- Jaime
>>
>>
>> On May 15, 2008, at 1:38 PM, Jaime Vargas wrote:
>>
>>> Still no luck. Am I missing something stupid?
>>>
>>> nerd% ./zpty-test.zsh
>>> +./zpty-test.zsh:4> zmodload zsh/zpty
>>> +./zpty-test.zsh:8> zpty scppty scp hello.world 'user@host:~/'
>>> +./zpty-test.zsh:9> zpty -t scppty
>>> +./zpty-test.zsh:10> zpty -r scppty line assword:
>>>
>>> #!/opt/csw/bin/zsh
>>> set -x
>>> zmodload zsh/zpty
>>> die() {print -r -- $1 >&2; exit 1;}
>>> zpty scppty scp hello.world user@host:~/
>>> zpty -t scppty || die "fuck"
>>> zpty -r scppty line "assword:" || die "no password asked"
>>> zpty -w scppty "TopSecret"
>>> while zpty -r scppty line;
>>>    do
>>>        result+="$line"$'\n'
>>>    done
>>> zpty -d scppty
>>> print $result
>>>
>>> On May 15, 2008, at 1:03 PM, Stephane Chazelas wrote:
>>>
>>>> On Thu, May 15, 2008 at 12:00:25PM -0400, Jaime Vargas wrote:
>>>>> Still doesn't work for me. Below is the modified script and the  
>>>>> debug
>>>>> output.
>>>>>
>>>>> #!/opt/csw/bin/zsh
>>>>>
>>>>> set -x
>>>>>
>>>>> zmodload zsh/zpty
>>>>>
>>>>> die() {print -r -- $1 >&2; exit 1;}
>>>>>
>>>>> zpty scppty scp hello.world jvargas@aoma6000-4-9.aoma.rhbss.com:~/
>>>>> zpty -t scppty || die "fuck"
>>>>> zpty -r scppty line "*:" || die "no password asked"
>>>>> zpty -w scppty "3lp&tbw"
>>>>> while zpty -r scppty line;
>>>>>    do
>>>>>        result+="$line"$'\n'
>>>>>    done
>>>>> zpty -d scppty
>>>>> print $result
>>>>>
>>>>> I changed my credentials for security. Basically it now hangs  
>>>>> waitng for
>>>>> password and doesnt' do anything.  -- Jaime
>>>>>
>>>>> nerd% ./zpty-test.zsh
>>>>> +./zpty-test.zsh:5> zmodload zsh/zpty
>>>>> +./zpty-test.zsh:10> zpty scppty scp hello.world 'luser@host:~/'
>>>>> +./zpty-test.zsh:11> zpty -t scppty
>>>>> +./zpty-test.zsh:12> zpty -r scppty line '*:'
>>>>
>>>> Had you printed $line, you'd have seen something like
>>>> "+myscript:", not "Passwd: ".
>>>>
>>>>
>>>> [...]
>>>>> +./zpty-test.zsh:14> zpty -r scppty line
>>>> [...]
>>>>
>>>> As Peter said, if you don't provide with a pattern to look for,
>>>> zpty will look for NL characters.
>>>>
>>>> That last zpty is probably still waiting because so far, it has
>>>> only received "Password: " and is waiting for a NL character
>>>> that will never come.
>>>>
>>>> So, in your code above, you should wait for something more
>>>> specific than just ":":
>>>>
>>>> zpty -r scppty line "assword: " || die "no password asked"
>>>>
>>>> for instance.
>>>>
>>>> -- 
>>>> Stéphane
>>>
>>
>


  reply	other threads:[~2008-05-20 14:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-15 12:02 zpty woes Jaime Vargas
2008-05-15 13:10 ` Stephane Chazelas
2008-05-15 13:18 ` Peter Stephenson
2008-05-15 14:50   ` Stephane Chazelas
2008-05-15 15:26     ` Peter Stephenson
2008-05-15 16:25     ` Jaime Vargas
2008-05-15 16:36       ` * " Peter Stephenson
     [not found]     ` <99E8D43E-EC34-48DB-A5AD-BFA197A3AAA3@mac.com>
2008-05-15 17:03       ` Stephane Chazelas
     [not found]       ` <480CEB80051F27AE@mac.com>
2008-05-15 17:38         ` Jaime Vargas
2008-05-15 17:53           ` Jaime Vargas
2008-05-20  3:25             ` Jaime Vargas
2008-05-20 14:28               ` Jaime Vargas [this message]
2008-05-20 16:25                 ` zpty woes (enhancement request) Bart Schaefer
2008-05-15 13:26 ` zpty woes Stephane Chazelas
2008-05-15 15:44   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5BA613C5-8227-4803-AFD1-EA2AF754DB20@mac.com \
    --to=jev@mac.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).