gpt4 book ai didi

linux - 如何在脚本中输入密码和用户名

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:22 25 4
gpt4 key购买 nike

我写了一个 shell 脚本,我将把它设置到 crontab 中,但我遇到了问题。当 crontab 运行我的脚本时,在脚本中运行 scp 命令并从不同的服务器获取一些信息,因此我必须在我的脚本中输入其他服务器的密码。如何在脚本中输入密码?

我的脚本:

scp username@host:/Products/data/bridge/control.txt .

????? ( have to automatically enter password)

b=$(more control.txt | wc -l)

if [$b = 1]; then

echo " OK "

fi

最佳答案

你可以使用expect,例如:

my_password="123456"
expect -c "spawn scp username@host:/Products/data/bridge/control.txt .; expect \"password\" {send -- \"${my_password}\r\"; expect eof;};"

关于linux - 如何在脚本中输入密码和用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46768845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com