From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12530 invoked from network); 20 May 2008 03:25:26 -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=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 03:25:26 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 23510 invoked from network); 20 May 2008 03:25:18 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 20 May 2008 03:25:18 -0000 Received: (qmail 3963 invoked by alias); 20 May 2008 03:25:13 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25074 Received: (qmail 3949 invoked from network); 20 May 2008 03:25:12 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 20 May 2008 03:25:12 -0000 Received: from smtpoutm.mac.com (smtpoutm.mac.com [17.148.16.68]) by bifrost.dotsrc.org (Postfix) with ESMTP id 8300680589A4 for ; Tue, 20 May 2008 05:25:08 +0200 (CEST) Received: from mac.com (asmtp010-s [10.150.69.73]) by smtpoutm.mac.com (Xserve/smtpout005/MantshX 4.0) with ESMTP id m4K3P7g9004376 for ; Mon, 19 May 2008 20:25:07 -0700 (PDT) Received: from zinn-desktop1.us.randomhouse.com (pool-71-191-51-76.washdc.fios.verizon.net [71.191.51.76]) (authenticated bits=0) by mac.com (Xserve/asmtp010/MantshX 4.0) with ESMTP id m4K3P3Lj020179 for ; Mon, 19 May 2008 20:25:04 -0700 (PDT) Message-Id: From: Jaime Vargas To: Zsh hackers list In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Re: zpty woes Date: Mon, 19 May 2008 23:25:02 -0400 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> X-Mailer: Apple Mail (2.919.2) X-Virus-Scanned: ClamAV 0.91.2/7177/Tue May 20 04:18:25 2008 on bifrost X-Virus-Status: Clean 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 of =20 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 for =20= > 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 >> >