在没有预料到的命令询问时,通过bourne shell脚本输入密码

时间:2021-01-06 14:39:54

I am writing a bourne shell script for the openwrt firware where I want to copy my files from router to linux machine. when i do

我正在为openwrt firware编写一个bourne shell脚本,我想将我的文件从路由器复制到linux机器。当我做

scp /etc/clients.txt shah@192.168.1.2:/home/shah/

from inside the router's openwrt firmware, it asks me to give the password. I want to give this password from within the script because this file needs to be copied after every 2 seconds. How can I do this without using expect?

从路由器的openwrt固件内部,它要求我提供密码。我想在脚本中提供此密码,因为此文件需要在每2秒后复制一次。如何在不使用期望的情况下完成此操作?

1 个解决方案

#1


1  

You can try to use sshpass tool but you will need to provide a password in clear text in your script. If that is not a problem you should use it.

您可以尝试使用sshpass工具,但需要在脚本中以明文形式提供密码。如果这不是问题,你应该使用它。

sshpass -p 'password'  scp /etc/clients.txt shah@192.168.1.2:/home/shah/

#1


1  

You can try to use sshpass tool but you will need to provide a password in clear text in your script. If that is not a problem you should use it.

您可以尝试使用sshpass工具,但需要在脚本中以明文形式提供密码。如果这不是问题,你应该使用它。

sshpass -p 'password'  scp /etc/clients.txt shah@192.168.1.2:/home/shah/