On Friday, 15 July 2022 18:39:25 CEST Grant Taylor wrote:
> On 7/14/22 3:22 PM, Steve Wilson wrote:
> > Have you looked at dev-tcltk/expect?
> 
> Expect has it's place.
> 
> Just be EXTREMELY careful when using it for anything security related.

I agree

> Always check for what is expected before sending data.  Don't assume
> that something comes next and blindly send it (possibly after a pause).
> 
> Things break in a really weird and unexpected way.  (No pun intended.)
> 
> Also, do as much logic outside of expect as possible.  E.g. don't try to
> add a user and then respond to a failure.  Instead check to see if the
> user exists /before/ trying to add it.

I've been using ansible for some of my automation scripts and am happy with 
the way that works. The existing implementations for "adding users" and such 
is tested plenty by others and does actually check if the user exists before 
trying to add one.

> Plan on things failing and try to control the likely ways that it can fail.
> 
> Paying yourself forward with time and effort developing (expect) scripts
> will mean that you reap the rewards for years to come.

I only use expect to automate the login-process as mentioned in the original 
email. The line it's expecting is more then just "*?assword" like in all the 
examples.

Currently, SSH puts the password-prompt as:
(<username>@<hostname>) Password:

As I know both, the expected string is this full line. If SSH changes its 
behaviour, the script will simply fail.

--
Joost



Reply via email to