当前位置:网站首页 / Linux / 正文

linux服务器文件自动上传到指定ftp目录sh脚本

时间:2019年01月11日 | 作者 : liuhui | 分类 : Linux | 浏览: 7381次 | 评论 0

阿里云限量代金券 | 此广告位出租25元/月

首先安装ftp命令

CentOS:

yum install ftp -y

Debian/Ubuntu:

apt-get install ftp -y


创建backup.sh脚本文件,将下面的代码复制进去,只需要修改updir、todir、ip、user、password这五个地方就可以了

#!/bin/bash 
updir=/root/sk    #要上传的文件夹
todir=sk          #目标文件夹
ip=127.0.0.1      #服务器
user=leo          #ftp用户名
password=123456        #ftp密码
sss=`find $updir -type d -printf $todir/'%P\n'| awk '{if ($0 == "")next;print "mkdir " $0}'` 
aaa=`find $updir -type f -printf 'put %p %P \n'` 
ftp -nv $ip <<EOF 
user $user $password
type binary 
prompt 
$sss 
cd $todir 
$aaa 
quit 
EOF

执行脚本命令

sh ./backup.sh

添加cron计划任务,每天21:30分执行一下backup.sh脚本

crontab -e

30 21 * * * sh /root/backup.sh

推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信