Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash,密码不能传入_Bash_Passwords_Expect_Scp_Spawn - Fatal编程技术网

bash,密码不能传入

bash,密码不能传入,bash,passwords,expect,scp,spawn,Bash,Passwords,Expect,Scp,Spawn,我正在尝试使用scp,我需要与w/沟通的盒子没有钥匙。 我在网上搜索时尝试了这段代码和它的许多变体,但由于某些原因它没有被输入。 如果你能帮助我,那就太好了。提前谢谢。 顺便说一句,我正在执行mac上测试的bash脚本 #!/bin/bash #$1- source file #$2- destination #$3- password /usr/bin/expect << EOF spawn scp -rp $1 $2 set pass $3 expect -re "pass

我正在尝试使用scp,我需要与w/沟通的盒子没有钥匙。 我在网上搜索时尝试了这段代码和它的许多变体,但由于某些原因它没有被输入。 如果你能帮助我,那就太好了。提前谢谢。 顺便说一句,我正在执行mac上测试的bash脚本

#!/bin/bash

#$1- source file
#$2- destination
#$3- password

/usr/bin/expect << EOF
spawn scp -rp $1  $2
set pass $3
expect -re "password:"
send "password\r" 
expect "\r"
send "\r\n"
EOF

您必须等待
scp
命令的
文件结束(eof)

#!/bin/bash

#$1- source file
#$2- destination
#$3- password

/usr/bin/expect << EOF
spawn scp -rp $1  $2
set pass $3; # Instead, you can also directly use the '$3' for password
puts "pwd = \$pass"
expect -re "password:"
send "\$pass\r" 
expect eof
EOF
注意:如果您的文件太大,所需时间超过
的默认超时时间(即10秒),则应增加
超时值

它可以通过以下方式实现:

set timeout 60; # This will make the timeout value to '1 min'

谢谢你,我想这应该是在expect中使用的,对吗?是的,文件相当大,准确地说是23M。我是否也应该使用interact语句?
interact
不需要。如上所述,增加
超时
dinesh@dinesh-VirtualBox:~/stackoverflow$ ./vmaxer srcfile dinesh@xxx.xxx.xx.xxx:/home/dinesh welcome!2E
spawn scp -rp srcfile dsivaji@xxx.xxx.xx.xxx:/home/dinesh
pwd = welcome!2E
dinesh@xxx.xxx.xx.xxx's password: 
srcfile                                                        100%  281     0.3KB/s   00:00    
dinesh@dinesh-VirtualBox:~/stackoverflow$ 
set timeout 60; # This will make the timeout value to '1 min'