码迷,mamicode.com
首页 > 系统相关 > 详细

linux批量远程多服务器FTP并下载文件的脚本

时间:2015-04-01 17:16:36      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

#!/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

linux批量远程多服务器FTP并下载文件的脚本

标签:

原文地址:http://www.cnblogs.com/franjia/p/4384109.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!