{"id":309,"date":"2013-07-12T16:54:17","date_gmt":"2013-07-12T16:54:17","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=309"},"modified":"2013-07-12T16:54:17","modified_gmt":"2013-07-12T16:54:17","slug":"shell-script-to-clear-the-mails-in-default-address-on-cpanel-server","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/07\/12\/shell-script-to-clear-the-mails-in-default-address-on-cpanel-server\/","title":{"rendered":"Shell script to clear the mails in \u201cDefault Address\u201d on cPanel Server"},"content":{"rendered":"<h3><strong>If you are trying to clear the Default (Catch-All) address on your cPanel accounts, you can use the following script. Just place it inside a file named clear.sh on the server, provide executable permission and run it.<\/strong><\/h3>\n<div>\n<blockquote>\n<pre>vi clear.sh<\/pre>\n<\/blockquote>\n<div><strong>Enter the following code, save and exit.<\/strong><\/div>\n<blockquote>\n<pre dir=\"ltr\">#!\/bin\/sh\nfor i in $(ls \/var\/cpanel\/users)\ndo\n rm -rf \/home\/$i\/mail\/cur\/*\n rm -rf \/home\/$i\/mail\/new\/*\n rm -f \/home\/$i\/mail\/maildirsize\ndone<\/pre>\n<\/blockquote>\n<div>\n<p><strong>Now execute using the following command.<\/strong><\/p>\n<blockquote>\n<pre>.\/clear.sh<\/pre>\n<\/blockquote>\n<h3><strong>OR<\/strong><\/h3>\n<p><strong>Navigate to\u00a0\u00a0WHM &gt; Tweak Settings &gt;&gt;\u00a0Initial default\/catch-all forwarder destination.<\/strong><\/p>\n<p><em>Forwarding destination for a new account\u2019s catch-all\/default address. (Users may modify this value via the Default Address interface in cPanel.)<\/em><\/p>\n<p><em>\u201cfail\u201d rejects the message and notifies the remote SMTP server; this is usually the best choice if you are getting mail attacks.<\/em><\/p>\n<p><em>\u201cblackhole\u201d accepts and processes the message but then silently discards it; this avoids notifying the remote SMTP server but violates SMTP RFC 5321 and generally should not be used.<\/em><\/p>\n<\/div>\n<p><strong>If you set this to \u201cFail\u201d, then emails sent to non-existing email accounts on the domain will be bounced back to the sender rather than try to deliver to the user\u2019s default email account. This will only apply to new accounts. Any previously existing accounts will need to have this changed in \/etc\/valiases from the following.<\/strong><\/p>\n<div>\n<blockquote>\n<pre>*: username<\/pre>\n<\/blockquote>\n<\/div>\n<p dir=\"ltr\"><strong>To the following:<\/strong><\/p>\n<div>\n<blockquote>\n<pre>*: :fail: No Such User Here<\/pre>\n<\/blockquote>\n<\/div>\n<p dir=\"ltr\"><strong>Make sure to backup your valiases file before modifying.<\/strong><\/p>\n<div>\n<blockquote>\n<pre>cp -rp \/etc\/valiases \/etc\/valiases.bakup<\/pre>\n<\/blockquote>\n<\/div>\n<p><strong>Now run the following.<\/strong><\/p>\n<blockquote>\n<pre>for i in `ls \/var\/cpanel\/users\/`;do replace \"*: $i\" \"*: :fail: No Such User Here\" -- \/etc\/valiases\/*;done<\/pre>\n<\/blockquote>\n<p>Done!!!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are trying to clear the Default (Catch-All) address on your cPanel accounts, you can use the following script. Just place it inside a file named clear.sh on the server, provide executable permission and run it. vi clear.sh Enter the following code, save and exit. #!\/bin\/sh for i in $(ls \/var\/cpanel\/users) do rm -rf [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[58],"tags":[136],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-cpanel-control-panel","tag-cpanel-clear-default-email-account"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}