{"id":33,"date":"2009-09-02T23:28:13","date_gmt":"2009-09-03T03:28:13","guid":{"rendered":"http:\/\/brucetimberlake.com\/blog\/?p=33"},"modified":"2009-09-02T23:28:31","modified_gmt":"2009-09-03T03:28:31","slug":"deleting-sendmail-files-based-on-string-content","status":"publish","type":"post","link":"https:\/\/brucetimberlake.com\/blog\/2009\/09\/02\/deleting-sendmail-files-based-on-string-content\/","title":{"rendered":"Deleting sendmail file pairs based on content"},"content":{"rendered":"<p>This one-liner will identify files containing a string, and then use some bash string manipulation to generate a wildcard for the pair of files sendmail creates for each message (dfn for message content, and Qfn for headers).  This assumes you&#8217;re running it in the mail queue directory (\/var\/spool\/mqueue for example).<\/p>\n<p><code><br \/>\nfor f in `grep -l -i viagra *`; do t=${f:10:6}; rm -f *${t}; done<br \/>\n<\/code><\/p>\n<p>The <code>${f:10:6}<\/code> extracts the last 6 characters of the filename, then the <code>rm<\/code> command prepends that with the wildcard.<\/p>\n<p>Some sample output:<\/p>\n<p><code><br \/>\n[root@mail mqueue]# grep -l -i cialis *<br \/>\ndfn7U8Rc3X020530<br \/>\ndfn7UD7BUh015512<br \/>\ndfn7VELCbV031687<br \/>\n<\/code><\/p>\n<p>But there are actually six files:<\/p>\n<p><code><br \/>\n[root@mail mqueue]# ls -l | egrep \"020530|015512|031687\"<br \/>\n-rw-------  1 root smmsp    2062 Aug 30 01:27 dfn7U8Rc3X020530<br \/>\n-rw-------  1 root smmsp    2232 Aug 30 06:07 dfn7UD7BUh015512<br \/>\n-rw-------  1 root smmsp    2069 Aug 31 07:21 dfn7VELCbV031687<br \/>\n-rw-------  1 root smmsp     825 Aug 30 01:27 Qfn7U8Rc3X020530<br \/>\n-rw-------  1 root smmsp     837 Aug 30 06:07 Qfn7UD7BUh015512<br \/>\n-rw-------  1 root smmsp     810 Aug 31 07:21 Qfn7VELCbV031687<br \/>\n<\/code><\/p>\n<p>So we run the command, using cialis:<\/p>\n<p><code><br \/>\nfor f in `grep -l -i cialis *`; do t=${f:10:6}; rm -f *${t}; done<br \/>\n<\/code><\/p>\n<p>Then there are no more files \ud83d\ude42<\/p>\n<p><code><br \/>\n[root@mail mqueue]# for f in `grep -l -i cialis *`; do t=${f:10:6}; rm -f *${t}; done<br \/>\n[root@mail mqueue]# grep -l -i cialis *<br \/>\n[root@mail mqueue]#<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This one-liner will identify files containing a string, and then use some bash string manipulation to generate a wildcard for the pair of files sendmail creates for each message (dfn for message content, and Qfn for headers). This assumes you&#8217;re running it in the mail queue directory (\/var\/spool\/mqueue for example). for f in `grep -l &hellip; <a href=\"https:\/\/brucetimberlake.com\/blog\/2009\/09\/02\/deleting-sendmail-files-based-on-string-content\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Deleting sendmail file pairs based on content&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-sysadmin"],"_links":{"self":[{"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":3,"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":36,"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions\/36"}],"wp:attachment":[{"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brucetimberlake.com\/blog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}