我曾尝试编写一个脚本来从远程服务器下载文件,如下所示:
#!/bin/bash
######!/usr/bin/expect -f
# connect via scp
server='remoteserver@202.132.251.225'
pass='abcde12345'
remoteServerDesitination='/home/vijay/myHOMEdir'
file_to_get='amber9_installation_steps.txt'
directory_to_safe='/home/vijay/Simulation-Folders'
/usr/bin/expect << EOF
spawn scp "$server:$remoteServerDesitination/$file_to_get" $directory_to_safe
expect {
-re ".*sword.*" {
exp_send "$pass\n"
}
}
interact
EOF
当我执行此脚本时,它不会弹出任何错误,也不会下载任何文件。我无法找出遗漏的错误。
答案 0 :(得分:0)
您的期望脚本是否尝试为scp
提供密码?您可能最好使用密钥对,并完全跳过密码身份验证。尝试谷歌搜索“ssh keypair教程”获取有关设置的说明。
答案 1 :(得分:0)
使用sshpass
!
#!/bin/bash
SERVER=remoteserver@202.132.251.225
PASS=abcde12345
REMOTESERVERDESITINATION=/home/vijay/myHOMEdir
FILE_TO_GET=amber9_installation_steps.txt
DIRECTORY_TO_SAFE=/home/vijay/Simulation-Folders
sshpass -p $PASS scp $SERVER:$REMOTESERVERDESITINATION/$FILE_TO_GET $DIRECTORY_TO_SAFE