This is not working:
#!/usr/bin/env expect
spawn -noecho /scripts/clone_repos.sh
expect {(yes/no/[fingerprint])?}
send "yes\r"
expect {':}
send "admin\r"
expect {':}
send "superComplexPassword\r"
interact
First prompt should match
"Are you sure you want to continue connecting (yes/no/[fingerprint])? "
Second and Third:
"Username for 'https://changingDomain': "
"Password for 'https://changingDomain': "
Its only hanging on the last one. Locally it works, but on the Kubernetes pod it hangs. This is a PostSync Script embedded in an ArgoCD Project.
Edit:
Version 2: #!/usr/bin/env expect spawn -noecho /scripts/clone_repos.sh
expect -re {yes/no}
send "yes\r"
expect -re {^Username}
send "gitea_admin\r"
expect -re {^Password}
send -- "superSecretPass\r"
interact
This is working a lot better now! Still hanging strangely on the last input, the script just finishes without providing the password. The problem might lie in the containered setup. Is there a way to have more verbosity with expect?
This is not working:
#!/usr/bin/env expect
spawn -noecho /scripts/clone_repos.sh
expect {(yes/no/[fingerprint])?}
send "yes\r"
expect {':}
send "admin\r"
expect {':}
send "superComplexPassword\r"
interact
First prompt should match
"Are you sure you want to continue connecting (yes/no/[fingerprint])? "
Second and Third:
"Username for 'https://changingDomain': "
"Password for 'https://changingDomain': "
Its only hanging on the last one. Locally it works, but on the Kubernetes pod it hangs. This is a PostSync Script embedded in an ArgoCD Project.
Edit:
Version 2: #!/usr/bin/env expect spawn -noecho /scripts/clone_repos.sh
expect -re {yes/no}
send "yes\r"
expect -re {^Username}
send "gitea_admin\r"
expect -re {^Password}
send -- "superSecretPass\r"
interact
This is working a lot better now! Still hanging strangely on the last input, the script just finishes without providing the password. The problem might lie in the containered setup. Is there a way to have more verbosity with expect?
Share Improve this question edited Mar 31 at 22:43 Stephan Kristyn asked Mar 31 at 21:43 Stephan KristynStephan Kristyn 15.8k15 gold badges93 silver badges158 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 0As hinted at https://unix.stackexchange/questions/693807/how-to-correctly-use-spawn-expect-send-for-git-push
..after you send the password, you don't wait for the push to complete: the expect script runs out of commands to run and exits too early, killing the git process. After any send, you should expect something. In this case, you're expecting the spawned command to end which is denoted with expect eof
So, adding a set timeout -1
and an expect eof
at the end did the trick for me, even in the a challenging Kubernetes-based GitOps environment.
#!/usr/bin/env expect
set PASSWORD [exec cat password]
set USERNAME [exec cat username]
spawn -noecho /scripts/clone_repos.sh
expect "Are*"
send "yes\r"
expect "User*"
send "$USERNAME\r"
expect "Pass*"
send -- "$PASSWORD\r"
set timeout -1 ; # no timeout
expect eof
?
needs to be escaped in regular expressions. – Barmar Commented Mar 31 at 21:54?
has special meaning in regular expressions, it means the previous pattern is optional, or it's used to make non-greedy quantification. – Barmar Commented Mar 31 at 21:59expect -re
. – Barmar Commented Mar 31 at 22:03