[HN Gopher] Daniel J. Bernstein's ptyget toolset
       ___________________________________________________________________
        
       Daniel J. Bernstein's ptyget toolset
        
       Author : todsacerdoti
       Score  : 107 points
       Date   : 2022-04-21 12:31 UTC (10 hours ago)
        
 (HTM) web link (jdebp.uk)
 (TXT) w3m dump (jdebp.uk)
        
       | AceJohnny2 wrote:
       | > _In the 1990s Daniel J. Bernstein wrote a pty package, in order
       | to cheat at nethack._
       | 
       | Now I want to know more. I assume he was automating input to the
       | game? But how was he analyzing state?
        
         | assbuttbuttass wrote:
         | It's pretty easy to inspect the nethack state since it's all
         | text. When I wrote a script to reroll nethack characters in the
         | past, I just opened the inventory and used "grep" to search for
         | desired items.
        
       | nerdponx wrote:
       | I am curious with the use cases for something like this might be.
       | I feel like it's very rare nowadays to encounter a CLI/TUI
       | program that doesn't have a "non-interactive" alternative, either
       | in a different tool or built into the application itself.
       | 
       | I know that pexpect can be used for _testing_ such applications
       | though. Is this meant to be for a similar use case? Or were
       | "interactive-only" tools more common at one time in the past?
        
         | koolba wrote:
         | Does gpg have non-interactive mode yet? I vaguely recall
         | automating pass phrase entry being borderline impossible.
        
           | LukeShu wrote:
           | I've been doing non-interactive gpg without an issue since
           | 2014.
        
           | encryptluks2 wrote:
           | It has for a long time but it is still not ideal for editing
           | subkeys and what not.
        
         | dangerface wrote:
         | Bit of an edge use case but I had a backup server that the ssh
         | would only take a password from interactive keyboard wouldn't
         | accept the password argument for scp. Something like this could
         | have fixed the issue, I ended up just going for a different
         | provider that allowed ssh keys.
        
           | pgCKIN wrote:
           | IIRC I've used the expect command more than once for similar
           | use cases.
        
           | quesera wrote:
           | There is also sshpass, which allows non-interactive ssh
           | password auth.
           | 
           | You can provide the password on the command line, or in an
           | environment variable:                 sshpass -p 'PASSWORD'
           | ssh user@host /bin/id       SSHPASS=PASSWORD sshpass -e ssh
           | user@host /bin/id
           | 
           | Not ideal, but if you're working with inflexible third
           | parties who don't understand public keys, sometimes it's
           | acceptable.
           | 
           | Storing secrets in environment variables is a common practice
           | in many mostly-reasonable orgs.
        
             | bruce_one wrote:
             | OpenSSH also supports using a script to get the password if
             | using the `SSH_ASKPASS` environment variable, and being
             | invoked under a non-tty input e.g.                 { echo
             | '#!/bin/sh' ; echo 'echo my_password' ; } > password.sh #
             | don't do it like this :-p       chmod +x password.sh
             | SSH_ASKPASS=./password.sh DISPLAY= setsid ssh user@host
             | /bin/id
             | 
             | In newer SSH versions `DISPLAY` is not required (but there
             | is a new `SSH_ASKPASS_REQUIRE` environment variable), but
             | in older (e.g. 8.x) versions, then it needs to be set as
             | the default ssh-ask-password was an X11 command, and I
             | believe the logic assumed that scenario.
        
         | scottlamb wrote:
         | I sometimes want "nobuf" or something like it. I run some
         | command that produces output promptly. Then I pipe it through
         | grep or tee and the output doesn't show up as promptly, because
         | it's switched from line buffering to block buffering. "nobuf"
         | fixes this.
         | 
         | There's a command called "stdbuf" on Linux systems that
         | accomplishes the same thing in a different way. It sets some
         | magic environment variables [1], and that tells the subprocess
         | to use line buffering, assuming it's using glibc [edit: or any
         | dynamically-linked libc] and stdio. No pty actually required
         | then.
         | 
         | stdbuf's manpage has an example:                      tail -f
         | access.log | stdbuf -oL cut -d ' ' -f1 | uniq            This
         | will immediately display unique entries from access.log
         | 
         | [1] edit: just checked. It injects its own code via the
         | LD_PRELOAD environment variable, and then controls that with
         | other environment variables. LD_PRELOAD is gross but it works,
         | I guess.
        
         | cduzz wrote:
         | I think automating nethack is sufficient reason for this tool.
        
           | tux3 wrote:
           | There's no wrong way to play, but savescumming makes it a
           | different kind of game!
           | 
           | Sadly the AIs (nethackchallenge.com) are not yet good enough
           | to show us what closer to optimal play looks like.
        
             | cduzz wrote:
             | I typically play on public servers to avoid any save game
             | temptations, or the reverse, removing terrifying bones
             | infested with rogue pet vampires and cursed artifacts...
             | 
             | I'm disappointed that DJB didn't automate polypiling until
             | he got what he wanted, rather than just rolling new
             | characters until getting the desired combination of
             | resources. At that point, I'd just say that save game
             | editing and RNG grinding are comparable...
             | 
             | If you're reading this, DJB, thanks for all the awesome and
             | weird tools! Perhaps you're not as widely attributed as you
             | should be but I see your influences everywhere in modern
             | unix.
             | 
             | (edited to change "fingerprints" to "influences" -- things
             | like systemd or the later solaris init replacement are
             | clearly a funhouse mirror re-imagning of daemontools and
             | family -- but fingerprints implies that DJB touched these
             | things which I'm pretty confident he didn't)
        
       | VectorLock wrote:
       | >What's pty good for? I wrote the first versions of pty so that I
       | could run pty nethack inside a script which would keep rerolling
       | characters until I had both a ring of polymorph and a ring of
       | polymorph control
       | 
       | Funny I wrote the same kind of start-scumming script against
       | nethack.org using Python and pexpect.
        
       | HerrMonnezza wrote:
       | `empty` is a similar tool.
       | 
       | Source (clone of the original SF repo):
       | https://github.com/ierton/empty
       | 
       | Man page:
       | http://manpages.ubuntu.com/manpages/trusty/man1/empty.1.html
        
       ___________________________________________________________________
       (page generated 2022-04-21 23:01 UTC)