简体   繁体   中英

How does Linux Expect script work?

I ever tried to input password by I/O redirection like echo <password> | ssh <user>@<host> echo <password> | ssh <user>@<host> , but it didn't work of course. Then I got that ssh actually reads password directly from /dev/tty instead of STDIN, so I/O redirection doesn't work for it.

As far as I know, Expect script is the standard way for this kind of job. I'm curious about how Expect works? I guess it runs the target program in a child process, and it changes the /dev/tty of the child process to refer to another place, but I don't know how.

It uses something called a pseudo-TTY which looks to the called program like a TTY, but allows for programmed control. See eg Don Libes' Exploring Expect p498f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM