在脚本中使用等待

发布于 2024-10-04 22:06:19 字数 529 浏览 0 评论 0原文

在下面的期望脚本中,我注意到该脚本甚至在提示输入密码之前就会发送密码。如何防止这种情况发生?我可以使用等待语句或其他什么吗?

#!/usr/bin/expect -f
#set timeout 25
spawn rsync [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/
expect "[email protected]'s password: $"
send "\$xxxxxx\n"
expect "\\$ $

In the following expect script, I noticed that the script will send the password even before prompted for the password. How can this be prevented? Could I use a wait statement or something?

#!/usr/bin/expect -f
#set timeout 25
spawn rsync [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/
expect "[email protected]'s password: $"
send "\$xxxxxx\n"
expect "\\$ $

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲歌长辞 2024-10-11 22:06:19

您甚至不需要使用 expect 来完成此任务。根据手册页,rsync支持直接从文件读取密码的选项:

rsync --password-file=file_that_password_is_in [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/

或者使用环境变量:

export RSYNC_PASSWORD=secret
rsync [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/

You shouldn't even need to use expect for this task. According to the man page, rsync supports an option to read a password directly from a file:

rsync --password-file=file_that_password_is_in [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/

Or using an environment variable:

export RSYNC_PASSWORD=secret
rsync [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文