12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

postfix受信済みと配送不能メールの自動削除

Last updated at Posted at 2015-08-21

万が一サーバに入られて個人情報を抜かれない為に
こんなシェルを書いてみた

mail-delete.sh
#!/bin/sh

############################################
#配送不能キューに溜まったメールを廃棄する
############################################
postsuper -d ALL defer
postsuper -d ALL deferred

############################################
#curに移動してから一日経過したメールを削除する
############################################
function delete_file () {

	###################
	#debug用
	#ls -la /home/$1/Maildir/cur/
	#echo -e "削除対象のメールはこちら============================\n"
	#find /home/$1/Maildir/cur/ -ctime +1 -type f;
	#find /home/$1/Maildir/cur/ -ctime +1 -type f >> /var/log/cron;
	#echo -e "====================================================\n"
	find /home/$1/Maildir/cur/ -ctime +1 -type f -exec rm -f {} \;
}

############################################
# /home直下のdirだけ取得し、delete_fileを呼び出す
############################################
ls -F /home | grep / | while read line; do
	
	if [ -d /home/$line/Maildir ]; then
		delete_file $line;
	fi

done

あとはシェルをcronで実行するだけ!(毎日0時)

/etc/cron.d/mail-delete
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
0 0 * * * root /etc/cron.d/mail-delete.sh
12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?