Thursday, May 4, 2017

email all users that have exceeded their /home/ size quota with oneliner in du, perl

du -skh /home/* 2> /dev/null | sort -h | perl -pe 'if (/^\d{3}M/){ ($sz,$who) = $_=~ m!(\S+)\s\/home\/[a-z]{1,2}(75\d+)$!mxi;if ($who) {open(MAIL, "|/usr/sbin/sendmail -t");print MAIL "To: $who\@company.com\nFrom: mightymouse\@company.com\nSubject: homedir size exceeds: $sz; please remove items from your /home/ directory on uwb00078\n\nhomedir current size exceeds $sz > 99.9M; please remove items from your /home/ directory on uwb00078!";close(MAIL);print "$who $sz\n"}} $_=undef'

No comments:

Post a Comment