From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23172 invoked from network); 20 May 2008 14:28:53 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 20 May 2008 14:28:53 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 17937 invoked from network); 20 May 2008 14:28:49 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 20 May 2008 14:28:49 -0000 Received: (qmail 25613 invoked by alias); 20 May 2008 14:28:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25076 Received: (qmail 25593 invoked from network); 20 May 2008 14:28:44 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 20 May 2008 14:28:44 -0000 Received: from smtpoutm.mac.com (smtpoutm.mac.com [17.148.16.83]) by bifrost.dotsrc.org (Postfix) with ESMTP id 9D87A80589A4 for ; Tue, 20 May 2008 16:28:38 +0200 (CEST) Received: from smtpin126.mac.com (smtpin126-bge351000 [10.150.68.126]) by smtpoutm.mac.com (Xserve/smtpout020/MantshX 4.0) with ESMTP id m4KESbwP029778 for ; Tue, 20 May 2008 07:28:37 -0700 (PDT) MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Received: from [192.168.1.254] (static-141-157-25-210.balt.east.verizon.net [141.157.25.210]) by smtpin126.mac.com (Sun Java(tm) System Messaging Server 6.3-6.03 (built Mar 14 2008; 32bit)) with ESMTPA id <0K160088987MTZ40@smtpin126.mac.com> for zsh-workers@sunsite.dk; Tue, 20 May 2008 07:28:37 -0700 (PDT) In-reply-to: References: <34AE8142-F5DA-44FD-96BA-61BDE12BC74E@mac.com> <200805151318.m4FDIvKS015244@news01.csr.com> <20080515145054.GC5190@sc.homeunix.net> <99E8D43E-EC34-48DB-A5AD-BFA197A3AAA3@mac.com> <480CEB80051F27AE@mac.com> Message-id: <5BA613C5-8227-4803-AFD1-EA2AF754DB20@mac.com> Cc: Zsh hackers list Content-transfer-encoding: quoted-printable From: Jaime Vargas Subject: Re: zpty woes (enhancement request) Date: Tue, 20 May 2008 10:28:33 -0400 To: Jaime Vargas X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: ClamAV 0.91.2/7180/Tue May 20 12:49:10 2008 on bifrost X-Virus-Status: Clean It would be nice if zpty had a call to inspect the pseudo-terminal =20 buffer. I find that `zpty -r' with or without pattern to be very =20 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 =20= > doTask and doShellTask are required because when invoking a shell =20 > script the prompt is repeated and if a read is not done twice then =20 > `zpty -d ch' will kill the session. This is kind of weird, the same =20= > happens with the `pwd' command. > > Is there a way to avoid this "double prompt" problem? (It is kind =20 > 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=3D'user' > pass=3D'topsecret' > supw=3D'topsecret' > host=3D'host' > > # TASKS > task1=3D'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 =20 >> 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+=3D"$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 =20= >>>>> 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+=3D"$line"$'\n' >>>>> done >>>>> zpty -d scppty >>>>> print $result >>>>> >>>>> I changed my credentials for security. Basically it now hangs =20 >>>>> 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. >>>> >>>> --=20 >>>> St=E9phane >>> >> >