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

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

 1 #!/bin/sh
 2 ### input parms ####
 3 # scp.sh <remoteIp> <remoteUser> <remoteFilePath> <localFilePath> <remotePasswd>
 4 
 5 if [ "$#" -eq "5" ] ; then
 6     echo "input parms[$#] is no correct,please input parms[5]!!!"
 7     exit $?
 8 fi
 9 remoteIp="$1"
10 remoteUser="$2"
11 remoteFilePath="$3"
12 localFilePath="$4"
13 remotePasswd="$5"
14 
15 command="scp -q ${remoteUser}@${remoteIp}:${remoteFilePath} $localFilePath"
16 
17 expect -c "
18                 set timeout 10;
19                 spawn $command;
20                 expect \"password\";
21                 send \"${remotePasswd}\n\";
22                 expect eof;
23 "

 

tftp 拷贝文件的脚本如下

 1 #!/bin/sh
 2 
 3 ### tftp.sh <remoteIp> <remoteFilename> <localFilePath>
 4 ###     $0           $1                 $2                         $3            #####
 5 test $# -eq "3" ; then echo "input parms[$#] is no correct!!!" && exit
 6 
 7 tftp $1 > /dev/null <<!
 8 get $2 $3     
 9 quit
10 !
11 
12     

 

转载于:https://www.cnblogs.com/dguangqin/archive/2013/02/27/2935925.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值