1.写一个脚本:
[15:49 root@oldboy /tmp]# vim /server/scripts/bak-etc.sh
#!/bin/bash
tar zcf /tmp/etc-`date +\%F`.tar.gz /etc/
2.把脚本写入到定时任务里
crontab -e
00 00 * * * sh /server/scripts/bak-etc.sh >/dev/null 2>&1
1.写一个脚本:
vim /server/scripts/bak-etc.sh
#!/bin/bash
tar zcf /tmp/etc-`date +\%F.tar.gz /etc/
find /tmp/ -type f -mtime +7 -name 'etc*.tar.gz'|rm -rf
2.把脚本写入到定时任务里
00 00 * * * sh /server/scripts/bak-etc.sh >/dev/null 2>&1
1.写一个脚本:
#!/bin/bash
. /etc/profile
tar zcf /tmp/etc-`date +\%F_%w`.tar.gz /etc/
rm -f `find /tmp/ -type f -mtime +7 ! -name '*_1.tar.gz'`
2.把脚本写入到定时任务里
00 00 * * * sh /server/scripts/bak-etc.sh >/dev/null 2>&1
1.写一个脚本:
#!/bin/bash
. /etc/profile
mkdir /backup/`ip a s eth0 |awk -F'[ /]+' 'NR==3{print $3}'`_`date +\%F_%w`
tar zcf /backup/`ip a s eth0 |awk -F'[ /]+' 'NR==3{print $3}'`_`date +\%F_%w`/etc-`date +%F_%H.tar.gz` /etc/
2.把脚本写入到定时任务里
00 00 * * * sh /server/scripts/bak-etc.sh >/dev/null 2>&1
1.写一个脚本:
#!/bin/bash
dir=`ip a s eth0 |awk -F'[ /]+' 'NR==3{print $3}'`
mkdir /backup/`ip a s eth0 |awk -F'[ /]+' 'NR==3{print $3}'`_`date +\%F_\%T_\%w`
tar zcf /backup/dir/etc-`date +\%F_\%w`.tar.gz /etc/
rm -f `find /backup/ -type f -mtime +7 ! -name '*_1.tar.gz'`
2.把脚本写入到定时任务里
00 00 * * * sh /root/shells/bak-etc.sh >/dev/null 2>&1
1.写一个脚本:shells/nginx.sh
#!/bin/bash
find /var/log/nginx/ -type f –size +1G –name"*.log" -mtime +7 -exec mv {} /data/log/`date -d '-1 day'` \;
2.把脚本写入到定时任务里
00 00 * * * sh /root/shells/nginx.sh >/dev/null 2>&1
1.写一个脚本:shells/etc.sh
#!/bin/bash
tar /root/backup/`date +\%Y\%m\%d`_etc /etc/
2.把脚本写入到定时任务里
00 00 01 * * sh /root/etc.sh >/dev/null 2>&1
【面试题】定时任务
https://www.jianshu.com/p/d902ef6d3cf5
预习:
磁盘管理 raid 分区mbr 命令
网友评论