{"id":4416,"date":"2025-03-27T15:40:00","date_gmt":"2025-03-27T15:40:00","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=4416"},"modified":"2025-03-27T15:40:02","modified_gmt":"2025-03-27T15:40:02","slug":"check-file-for-contents-then-send-email-without-mailtools","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=4416","title":{"rendered":"Check File for Contents then Send Email (without mailtools)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A simple BASH script that you can run as a CRON job to check if a particular string is present in a file, and if not it sends you an email to say the file no longer has a particular string. And the email send just uses sendmail (assuming that is installed and configured).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can manually run the script if you wish, say if you called it &#8220;checkstring.sh&#8221;, with: <strong>.\/checkstring.sh<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nif grep -q 'mystring' \"\/root\/myfile.txt\";\nthen\n  echo -n \"String:\"\n  echo -e \"\\e&#91;31m Present\\e&#91;0m\"\nelse\n  echo -n \"String:\"\n  echo -e \"\\e&#91;32m No longer present!\\e&#91;0m\"\n  \/usr\/lib\/sendmail bob@domain.com &lt; \/root\/message.txt\nfi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The content of the message.txt file is something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>From: sender@domain.com\nTo: bob@domain.com\nSubject: String is no longer present!\nHello!\n\nIt looks like the string has gone!\n\nThanks\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A simple BASH script that you can run as a CRON job to check if a particular string is present in a file, and if not it sends you an email to say the file no longer has a particular string. And the email send just uses sendmail (assuming that is installed and configured). You &#8230; <a title=\"Check File for Contents then Send Email (without mailtools)\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=4416\" aria-label=\"Read more about Check File for Contents then Send Email (without mailtools)\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-4416","post","type-post","status-publish","format-standard","hentry","category-random"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4416"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4416\/revisions"}],"predecessor-version":[{"id":4417,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4416\/revisions\/4417"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}