在写bash时遇到一个问题,从远程scp文件到本地,需要输入密码,如何自动实现该过程?
#!/bin/bash
#file_name: expect_1.sh
src_host=192.168.1.103
src_pwd=tom@ether
src_path=/home/chi/server2.c
src_user=chi
expect -c "
spawn scp ${src_user}@${src_host}:${src_path} .
expect \"password:\"
send \"${src_pwd}\r\"
expect eof
"
[chi@yitai01 ~]$ ./expect_1.sh
spawn scp chi@192.168.1.103:/home/chi/server2.c .
Address 192.168.1.103 maps to yitai02, but this does not map back to the address - POSSIBLE BREAKIN ATTEMPT!
chi@192.168.1.103's password:
server2.c 100% 1969 1.9KB/s 00:00
看到了吧,不用手工输入密码输入,jiu ke yi copy.
#!/bin/bash
#file_name: expect_1.sh
src_host=192.168.1.103
src_pwd=tom@ether
src_path=/home/chi/server2.c
src_user=chi
expect -c "
spawn scp ${src_user}@${src_host}:${src_path} .
expect \"password:\"
send \"${src_pwd}\r\"
expect eof
"
[chi@yitai01 ~]$ ./expect_1.sh
spawn scp chi@192.168.1.103:/home/chi/server2.c .
Address 192.168.1.103 maps to yitai02, but this does not map back to the address - POSSIBLE BREAKIN ATTEMPT!
chi@192.168.1.103's password:
server2.c 100% 1969 1.9KB/s 00:00
看到了吧,不用手工输入密码输入,jiu ke yi copy.
源代码图片:
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27042095/viewspace-745587/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27042095/viewspace-745587/