干货
cd /var/spool/postfix/maildrop
rm *
lsof |grep deleted|awk '{print $2}'|xargs kill -9
*/10 * * * * /tmp/test.sh >/dev/null 2>&1
在Linux或Unix系统中,通过使用rm删除文件的原理,rm命令只是从文件系统的目录结构上解除链接(unlink),也就是说如果文件是被打开的(有一个进程正在使用该文件句柄),那该进程还是可以读取已删除的文件,删除的时候文件正在被使用中,所以并不释放磁盘空间。
可以杀死使用删除文件的进程来释放空间。
lsof |grep deleted|awk ‘{print $2}’|xargs kill -9
/var 100% ,后经查看发现是 /var/spool/postfix/maildrop 有大量文件.
发现是crontab 每次执行任务后会发送邮件,接受者是在他的配置文件 “/etc/crontab” 通过 MAILTO=root’ 来设置的,默认是root,如果执行输出没有十分必要要用邮件发送的话,可以修改此处。
下面是两个解决方法
方法一:
修改“/etc/crontab”
将‘MAILTO=root’替换成‘MAILTO=""’修改之后没有成功,需要重启crond服务才可以
也可从在crontab(crontab -e)中最前面直接加入MAILTO=""
方法二:
如果是我们不关心的备注型等输出我们完全可以让其输出到 /dev/null 这样就不会因为发送失败到导致在/var/spool/postfix/maildrop下面产出什么文件。
例如:
*/10 * * * * /tmp/test.sh >/dev/null 2>&1
经过测试发现果然没有再出现新增的文件。当然如果输出内容有需要保存的话,可以输出到指定文件。比如下面这样
*/10 * * * * /tmp/test.sh >/log/test.log
重启crontab服务
service cron stop
service cron status
* cron.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2020-12-14 16:55:57 CST; 8s ago
Process: 5022 ExecStart=/usr/sbin/cron -n (code=exited, status=0/SUCCESS)
Main PID: 5022 (code=exited, status=0/SUCCESS)
Dec 14 16:55:02 libossnx-11 cron[11417]: pam_systemd(crond:session): Failed to connect to system bus: Resource temporarily unavailable
Dec 14 16:55:02 libossnx-11 CRON[11385]: (web) CMD (/web/jsonproc/JSON_B2GPSP_ORDER_ADD.sh >>/log/cronlog/JSON_B2GPSP_ORDER_ADD.log)
Dec 14 16:55:26 libossnx-11 CRON[11425]: pam_unix(crond:session): session closed for user web
Dec 14 16:55:26 libossnx-11 CRON[11114]: pam_unix(crond:session): session closed for user web
Dec 14 16:55:26 libossnx-11 CRON[10823]: pam_unix(crond:session): session closed for user web
Dec 14 16:55:56 libossnx-11 systemd[1]: Stopping Command Scheduler...
Dec 14 16:55:56 libossnx-11 CRON[10734]: pam_unix(crond:session): session closed for user web
Dec 14 16:55:57 libossnx-11 CRON[11167]: pam_unix(crond:session): session closed for user web
Dec 14 16:55:57 libossnx-11 CRON[5241]: pam_unix(crond:session): session closed for user web
Dec 14 16:55:57 libossnx-11 systemd[1]: Stopped Command Scheduler.
libossnx-11:/etc/init.d # service cron start
libossnx-11:/etc/init.d # service cron status
* cron.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-12-14 16:56:20 CST; 44s ago
Main PID: 46198 (cron)
Tasks: 1 (limit: 65535)
CGroup: /system.slice/cron.service
`-46198 /usr/sbin/cron -n
Dec 14 16:57:01 libossnx-11 cron[51993]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[51999]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[51260]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[52004]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[51994]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[52007]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[52014]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[51987]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[51996]: pam_unix(crond:session): session opened for user web by (uid=0)
Dec 14 16:57:01 libossnx-11 cron[51990]: pam_unix(crond:session): session opened for user web by (uid=0)
crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (crontab_root installed on Mon Dec 14 16:45:24 2020)
# (Cronie version 4.2)
MAILTO=""
####/etc/sysctl.conf vm.drop_caches=3 or
####10 22 * * * echo 3 > /proc/sys/vm/drop_caches >/log/root.log