admin管理员组文章数量:1360337
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
本文标签: RegEx in Expect Script to match colon and questionmark followed by one whitespaceStack Overflow
版权声明:本文标题:RegEx in Expect Script to match colon and questionmark followed by one whitespace - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743919302a2561789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
?
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