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