6

linux下写crontab时注意输出重定向

 3 years ago
source link: https://houye.xyz/2018-08/cron/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
linux下写crontab时注意输出重定向

linux下写crontab时注意输出重定向

Table of Contents

问题和产生原因

今天发现开发服务器/var/spool/clientmqueue/目录下存在大量文件且占据了不小的存储, 一敲 ls ,直接占用6%的内存,而且半天没有反应。于是网上搜了一下 /var/spool/clientmqueue/目录下存在大量文件的原因及解决方法 ,原来是因为 crontab 的默认输出内容不断的被输出到该目录下,立即 crontab -l -u username 挨个看每个用户下的 crontab,果真发现有个用户下的定时任务没有重定向默认输出,而且执行频率是 每分钟

在没有重定向输出的 crontab 命令后面加上 >/dev/null 2>&1 ,即把默认输出和错误输出全部重定向到/dev/null。继续,切到/var/spool/clientmqueue/目录下,执行 find . -type f | xargs rm -vf 删除该目录下所有文件

Created: 2018-08-23 Thu 22:34

Emacs 24.5.1 (Org mode 8.2.10)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK