#!/bin/bash
date=$(date +%Y%m%d)
ago_date=$(date +%Y%m%d -d '2 day ago')
old_file=`ls | grep $ago_date`
echo $old_file
hosts_path=`ls /home/fanshikui/mysqlback170218 /home/fanshikui/backup_default_netcfg.sh /home/fanshikui/"test" `#路径自行修改,改完可以直接用
hosts_back=/root/"$date"hosts.back
#backfile=$date"$back".bak
#cat $hosts_path >$hosts_back
for back in $hosts_path
do
if [ -f $back ]; then
cat $back >"$back"$date.bak
fi
#backfile="$back".bak
backfile="$back"$date.bak
mv $backfile /root/
echo $backfile
done
#rm -rf `$old_file`
#echo $hosts_path
for deloldfile in $old_file
do
if [ -f $deloldfile ];then
rm -rf $deloldfile
fi
done
转载于:https://www.cnblogs.com/musen/p/6444008.html