{"id":803,"date":"2010-12-20T00:20:48","date_gmt":"2010-12-19T17:20:48","guid":{"rendered":"http:\/\/adityo.blog.binusian.org\/?p=803"},"modified":"2010-12-20T00:21:24","modified_gmt":"2010-12-19T17:21:24","slug":"shell-script-to-scan-for-any-files-changes-and-email-it","status":"publish","type":"post","link":"https:\/\/adityo.blog.binusian.org\/?p=803","title":{"rendered":"shell script to scan for any files changes and email it"},"content":{"rendered":"<p>Hi it has been along time since my last blog, i found this usefull script on this forum<a href=\"http:\/\/forums.asmallorange.com\/topic\/13649-shell-script-to-monitor-file-changes\/\"> http:\/\/forums.asmallorange.com\/topic\/13649-shell-script-to-monitor-file-changes\/<\/a>. I just want to share it \ud83d\ude42<\/p>\n<p>just go to your shell and create scan.sh files<\/p>\n<p># vim scan.sh<\/p>\n<p>and type this<\/p>\n<p>####################################################################################################################<\/p>\n<p>#!\/bin\/bash<\/p>\n<p>#Directory to search<br \/>\nmyDir=\/home\/username\/public_html<\/p>\n<p>#Set frequency of command in minutes, this should match how often you run the cron job<br \/>\nmyFrequency=&#8217;-30&#8242;<\/p>\n<p>#email address for mailing the results<br \/>\nmyEmail=email@address.com<\/p>\n<p>#Create datestamp for subject line<br \/>\n#This makes each subject line unique to prevent message collapsing in Gmail<br \/>\nmyDate=`date +%y-%m-%d`<br \/>\nmyTime=`date +%H:%M`<\/p>\n<p>#Test if files have been edited<br \/>\nfileCount=`find $myDir -mmin $myFrequency -type f | wc -l`<br \/>\nif [ $fileCount -gt 0 ]<br \/>\nthen<br \/>\n#Write the subject line and set correct form of the word &#8220;files&#8221; (singular or plural)<br \/>\nif [ $fileCount -eq 1 ]<br \/>\nthen<br \/>\nmySubject=&#8221;Attention! $fileCount File Modified on $myDate at $myTime&#8221;<br \/>\nelse<br \/>\nmySubject=&#8221;Attention! $fileCount Files Modified on $myDate at $myTime&#8221;<br \/>\nfi<\/p>\n<p>#execute find command and email the results<br \/>\nfind $myDir -mmin $myFrequency -type f | mail -s &#8220;$mySubject&#8221; $myEmail<br \/>\n#else nothing happens<br \/>\nfi<\/p>\n<p>####################################################################################################################<\/p>\n<p>then save it chmod 755 and run it (.\/scan.sh)<\/p>\n<p>or you can create crontab to run every 30 minute<\/p>\n<p># crontab -e<\/p>\n<p>*\/30 * * * * \/root\/scan.sh<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi it has been along time since my last blog, i found this usefull script on this forum http:\/\/forums.asmallorange.com\/topic\/13649-shell-script-to-monitor-file-changes\/. I just want to share it \ud83d\ude42 just go to your shell and create scan.sh files # vim scan.sh and type this #################################################################################################################### #!\/bin\/bash #Directory to search myDir=\/home\/username\/public_html #Set frequency of command in minutes, this should [&hellip;]<\/p>\n","protected":false},"author":386,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[713],"tags":[7130],"class_list":["post-803","post","type-post","status-publish","format-standard","hentry","category-ssh","tag-shell-script-to-scan-for-any-files-changes-and-email-it"],"_links":{"self":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/users\/386"}],"replies":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=803"}],"version-history":[{"count":2,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/803\/revisions"}],"predecessor-version":[{"id":805,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/803\/revisions\/805"}],"wp:attachment":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}