linux批量远程多服务器FTP并下载文件的脚本
#!/bin/bash
time=`date +%Y%m`
day=`date -d ‘-1 days‘ +%Y%m%d`
localDir="/DBBackup/GameDB"
cd $localDir
#ip_game.ini配置ftp服务器的ip,账号,密码等,格式自己定义
#比如:Server1 username userpasswd 1.1.1.1 Dbbackup
servername=(`cat /DBBackup/ip_game.ini | awk -F " " ‘{print $1}‘`)
user=(`cat /DBBackup/ip_game.ini | awk -F " " ‘{print $2}‘`)
passwd=(`cat /DBBackup/ip_game.ini | awk -F " " ‘{print $3}‘`)
ip=(`cat /DBBackup/ip_game.ini | awk -F " " ‘{print $4}‘`)
dbname=(`cat /DBBackup/ip_game.ini | awk -F " " ‘{print $5}‘`)
if [[ -z $time ]]
then
cd $time && mkdir $day
else
mkdir $time
cd $time && mkdir $day
fi
len=${#ip[*]}
num=0
while [ $num -lt $len ]
do
echo "=======${user[$num]}==========="
echo "=======${passwd[$num]}========="
echo "=======${ip[$num]}========="
cd $localDir/$time/$day
if [[ -z ${servername[$num]} ]]
then
cd ${servername[$num]}
else
mkdir ${servername[$num]}
fi
lftp ftp://${user[$num]}:"${passwd[$num]}"@${ip[$num]} <<END
lcd $localDir/$time/$day/${servername[$num]}
cd ${dbname[$num]}
echo ${dbname[$num]}
#mget empiregame_*_$(date +%Y%m%d).rar
mget empiregame_*_$(date -d ‘-1 days‘ +%Y%m%d)*.tar.gz
mget empireaccount_$(date -d ‘-1 days‘ +%Y%m%d)*.tar.gz
mget empirecards_$(date -d ‘-1 days‘ +%Y%m%d)*.tar.gz
mget empiregame_*_$(date -d ‘-1 days‘ +%Y%m%d)*.rar
bye
END
let num++
done
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。