Live data from Hacker News

Expect – Linux tool for automating interactive programs

linux.die.net

51–60 of 92 posts

Re: Expect – Linux tool for automating interactive programs

#51

My go-to example for `expect` is password-based SSH. Since we're all enlightened beings these days who surely never use this anymore, there's no risk to it: #!/bin/bash expect -c " spawn ssh user@10.0.0.1 expect \"password:\" send \"12345\r\" interact " `interact` hands you back control to do whatever you want, but you don't actually need to do that. You can have `expect` run every command, fill out every field. The…

You forgot all the other prompts that ssh might produce before the password prompt (e.g. add new host to known hosts yes/no). There are more possible prompts than most people realize.

Darn. If only there were a tool that can interactively answer prompts...

Re: Expect – Linux tool for automating interactive programs

#52
post #41

Earlier quoted context omitted.

For this particular use case, I'd suggest sshpass instead. https://linux.die.net/man/1/sshpass ... Operations folks today might not understand -- everything just works nowadays, which is slightly boring. And boring is good! But there's something unique about the feeling of making things work even though they are not designed to work, and really have no right to work. Expect has been a lifesaver for some of the most c…

Definitely, `sshpass` is the more better keyhole tool for this job. I picked it as the most common example I can imagine everyone going "ugh, I have to do this by hand again ?" at.

sshpass is a travesty of security.

It has all the pitfalls of putting your front door key under your doormat. Except you're doing it in a world where everyone can materialize a unique key out of thin air, and you can always instantly tell your door which of those keys should or shouldn't be allowed to open it.

sshpass is a curse, even calling it a crutch would be improper flattery. It's a dangerous cheat that accomplishes nothing except impeding people from otherwise spending the 20 minutes it takes to figure out SSH keys.

Re: Expect – Linux tool for automating interactive programs

#53

My go-to example for `expect` is password-based SSH. Since we're all enlightened beings these days who surely never use this anymore, there's no risk to it: #!/bin/bash expect -c " spawn ssh user@10.0.0.1 expect \"password:\" send \"12345\r\" interact " `interact` hands you back control to do whatever you want, but you don't actually need to do that. You can have `expect` run every command, fill out every field. The…

You forgot all the other prompts that ssh might produce before the password prompt (e.g. add new host to known hosts yes/no). There are more possible prompts than most people realize.

This isn't a script that we'd send on an unmanned, inter-planetary, mission. This could be something that can save the tedium of typing password on a daily basis. If it fails, well, we still have a reason to be alive: press ^C.

Re: Expect – Linux tool for automating interactive programs

#54
post #13

Linux tool? Hate when everything Unix automatically gets categorized as Linux. Have used Expect for many years for many use cases from automating servers to networking use cases as well.

I used to use it on HP-UX in the 90s.

Poor soul.

Re: Expect – Linux tool for automating interactive programs

#55

Earlier quoted context omitted.

Definitely, `sshpass` is the more better keyhole tool for this job. I picked it as the most common example I can imagine everyone going "ugh, I have to do this by hand again ?" at.

sshpass is a travesty of security. It has all the pitfalls of putting your front door key under your doormat. Except you're doing it in a world where everyone can materialize a unique key out of thin air, and you can always instantly tell your door which of those keys should or shouldn't be allowed to open it. sshpass is a curse, even calling it a crutch would be improper flattery. It's a dangerous cheat that accompl…

sometimes the device you're connecting to doesnt support ssh keys.

Re: Expect – Linux tool for automating interactive programs

#56
post #13

Linux tool? Hate when everything Unix automatically gets categorized as Linux. Have used Expect for many years for many use cases from automating servers to networking use cases as well.

https://news.ycombinator.com/item?id=41272562>

Re: Expect – Linux tool for automating interactive programs

#58

expect is one of those true love/hate things. Probably because the situations in which you need to use it are likely cursed. My time spent dealing with expect scripts is always miserable, and yet I don't know what I'd do without it

I've mostly used it for testing and scripting CLIs. Are there any better ways to do that?

try using charm bracelets vhs tool to script the tests, then get the demo video as an animated gif for free.

Re: Expect – Linux tool for automating interactive programs

#59

Earlier quoted context omitted.

sshpass is a travesty of security. It has all the pitfalls of putting your front door key under your doormat. Except you're doing it in a world where everyone can materialize a unique key out of thin air, and you can always instantly tell your door which of those keys should or shouldn't be allowed to open it. sshpass is a curse, even calling it a crutch would be improper flattery. It's a dangerous cheat that accompl…

sometimes the device you're connecting to doesnt support ssh keys.

[deleted]
Post reply on HN