您的位置:首页 > 编程语言 > PHP开发

scp或者tftp自动拷贝远端文件的脚本

2013-02-27 22:37 148 查看
linux的scp命令顾名思义就是拷贝文件,跟cp命令差不多,但是scp可以实现远端文件的拷贝,在CLI下面使用scp后会提示输入密码,下面使用脚本可以自动输入密码,如下

#!/bin/sh
### input parms ####
# scp.sh <remoteIp> <remoteUser> <remoteFilePath> <localFilePath> <remotePasswd>

if [ "$#" -eq "5" ] ; then
echo "input parms[$#] is no correct,please input parms[5]!!!"
exit $?
fi
remoteIp="$1"
remoteUser="$2"
remoteFilePath="$3"
localFilePath="$4"
remotePasswd="$5"

command="scp -q ${remoteUser}@${remoteIp}:${remoteFilePath} $localFilePath"

expect -c "
set timeout 10;
spawn $command;
expect \"password\";
send \"${remotePasswd}\n\";
expect eof;
"


tftp 拷贝文件的脚本如下

#!/bin/sh

### tftp.sh <remoteIp> <remoteFilename> <localFilePath>
###     $0           $1                 $2                         $3            #####
test $# -eq "3" ; then echo "input parms[$#] is no correct!!!" && exit

tftp $1 > /dev/null <<!
get $2 $3
quit
!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐