系统为 ubuntu
自己写了一脚本执行 tar 压缩文件:
#!/bin/sh tar -zcvf /home/j/backup/16/dbBackup/$(date +%y%m%d.tar.gz) db/ find /home/j/backup/16/dbBackup/ -type f -mtime +3 -exec rm -rf {} \; 单独执行不会出现错误,使用 crontab 定时执行在 mail 出现
Content-Type: text/plain; charset= Content-Transfer-Encoding: 8bit X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin> X-Cron-Env: <HOME=/home/j> X-Cron-Env: <LOGNAME=j> Message-Id: <20180313014101.506EF3C0072@j> Date: Tue, 13 Mar 2018 09:41:01 +0800 (CST) tar: db:无法 stat: 没有那个文件或目录 tar: 由于前次错误,将以上次的错误状态退出 crontab 文件为:
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * cd / && run-parts --report /etc/cron.hourly 25 6 * * * test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) # 41 9 * * * /home/j/backup/16/db.sh 