创建shell 脚本命令:
[email protected]:~# cat clearlog.sh
find /var/lib/postgresql/data/log/ -mtime +10 -name "*" -exec rm -rf {} /;
这个命令是find的基本用法,可以分两部分,find ~/ -name "*.aic"和 -exec rm -rf {} /;
~/:在根目录下查找
-name 查找文件名的方式
"*.aic"文件名中要求后缀是aic的所有文件
-exec 找到后执行命令
rm -rf {}命令就是删除文件
/;这是格式要求的,没有具体含义。
创建定时执行计划:
- 定时任务编辑命令:
crontab -e
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
# 文件中加入该行,表示每天0点执行命令 `sh /root/clearlog.sh`
* 0 * * * sh /root/clearlog.sh
重启cron 服务:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/1631.html