News for hackers. Stuff that matters.
Re:Daniel J. Bernstein's ptyget toolset by nerdponx on Thursday April 21, 2022 @09:55AM (#31109446)
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?

Re:Daniel J. Bernstein's ptyget toolset by scottlamb on Thursday April 21, 2022 @03:08PM (#31113910)
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.
Re:Daniel J. Bernstein's ptyget toolset by bandie91 on Friday April 22, 2022 @03:26AM (#31119164)
LD_PRELOAD is the greatest thing ever.
Re:Daniel J. Bernstein's ptyget toolset by cduzz on Thursday April 21, 2022 @10:49AM (#31110141)
I think automating nethack is sufficient reason for this tool.
Re:Daniel J. Bernstein's ptyget toolset by tux3 on Thursday April 21, 2022 @12:01PM (#31111230)
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.

Re:Daniel J. Bernstein's ptyget toolset by cduzz on Thursday April 21, 2022 @01:03PM (#31112094)
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)

Re:Daniel J. Bernstein's ptyget toolset by chongli on Friday April 22, 2022 @03:32AM (#31119199)
There are a bunch of aspects to optimal play in NetHack that are pretty unfun for humans to perform (but dramatically increase win rate). These things can all be programmed into an AI without too much trouble, some more fiddly than others:

* Always retrace your own steps when backtracking. Only walk on new tiles when it’s absolutely necessary for exploration. This greatly reduces your chances of stepping on unseen traps.

* Abuse shops to the max. Price ID everything you find. Sell every last bit of junk. Engage in credit cloning. Steal everything from shops.

* Abuse the protection racket. Max out on divine protection by spending all of the money from every shopkeeper’s pocket at the temple in minetown.

* Abuse alchemy to make large stacks of holy water and blessed potions of full healing. Increase your max HP to several hundred.

* Pudding farming. This one has thankfully been patched out.

* Polypiling. Polymorph lines of items on the floor. Try to get magic markers to write more scrolls of enchant armour.

Re:Daniel J. Bernstein's ptyget toolset by moonchild on Friday April 22, 2022 @01:47AM (#31118600)
not as consistent as the best humans yet, but they have won https://github.com/krajj7/BotHack
Re:Daniel J. Bernstein's ptyget toolset by dangerface on Thursday April 21, 2022 @11:17AM (#31110571)
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.
Re:Daniel J. Bernstein's ptyget toolset by quesera on Thursday April 21, 2022 @04:16PM (#31114660)
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.

Re:Daniel J. Bernstein's ptyget toolset by bruce_one on Thursday April 21, 2022 @06:37PM (#31116042)
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.
Re:Daniel J. Bernstein's ptyget toolset by pgCKIN on Thursday April 21, 2022 @12:07PM (#31111317)
IIRC I've used the expect command more than once for similar use cases.
Re:Daniel J. Bernstein's ptyget toolset by fmajid on Friday April 22, 2022 @04:39AM (#31119456)
The most common use-case I can think of (and one I've often wanted myself) is programs that only colorize when writing to a terminal, and you want to save the output but still keep the colors.
Re:Daniel J. Bernstein's ptyget toolset by koolba on Thursday April 21, 2022 @10:52AM (#31110188)
Does gpg have non-interactive mode yet? I vaguely recall automating pass phrase entry being borderline impossible.
Re:Daniel J. Bernstein's ptyget toolset by encryptluks2 on Thursday April 21, 2022 @12:15PM (#31111410)
It has for a long time but it is still not ideal for editing subkeys and what not.
Re:Daniel J. Bernstein's ptyget toolset by LukeShu on Thursday April 21, 2022 @11:11AM (#31110475)
I've been doing non-interactive gpg without an issue since 2014.