<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Shell Script for file monitoring in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069831#M94889</link>
    <description>Hi Sreejith, this is my script:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;FILE_DATE=`/bin/ls -al /etc/passwd | /bin/awk '{print $6 $7}'`&lt;BR /&gt;&lt;BR /&gt;DATE=`/bin/date | awk '{print $2 $3}'`&lt;BR /&gt;&lt;BR /&gt;if [ "$FILE_DATE" -eq "$DATE" ]&lt;BR /&gt;   then&lt;BR /&gt;        mailx -s "Check File (`hostname`)" name.surname@company.com &amp;lt; /etc/passwd&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Best regards.&lt;BR /&gt;Ernesto</description>
    <pubDate>Thu, 20 Sep 2007 02:53:41 GMT</pubDate>
    <dc:creator>Ernesto Cappello</dc:creator>
    <dc:date>2007-09-20T02:53:41Z</dc:date>
    <item>
      <title>Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069829#M94887</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I want to monitor a file and whenever it gets changed we should receive email notification regarding the same.&lt;BR /&gt;&lt;BR /&gt;For example: i want to monitor the file name "/etc/passwd". Once it is found that&lt;BR /&gt;the file is got changed then it should send email notification to Admin. &lt;BR /&gt;&lt;BR /&gt;Can any one suggest shell script for this ?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Sreejith</description>
      <pubDate>Thu, 20 Sep 2007 02:00:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069829#M94887</guid>
      <dc:creator>Sreejith Kumar</dc:creator>
      <dc:date>2007-09-20T02:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069830#M94888</link>
      <description>Hey&lt;BR /&gt;&lt;BR /&gt;check the time of the file with one of those commands:&lt;BR /&gt;&lt;BR /&gt;ls -l file (modification time)&lt;BR /&gt;ls -lc file (change time)&lt;BR /&gt;ls -lu file (access time)&lt;BR /&gt;&lt;BR /&gt;then compare it with the results of the check before, e.g. you check it each hour...&lt;BR /&gt;&lt;BR /&gt;if its's not the same time, send a mail.&lt;BR /&gt;&lt;BR /&gt;hope this helps&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Thu, 20 Sep 2007 02:18:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069830#M94888</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2007-09-20T02:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069831#M94889</link>
      <description>Hi Sreejith, this is my script:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;FILE_DATE=`/bin/ls -al /etc/passwd | /bin/awk '{print $6 $7}'`&lt;BR /&gt;&lt;BR /&gt;DATE=`/bin/date | awk '{print $2 $3}'`&lt;BR /&gt;&lt;BR /&gt;if [ "$FILE_DATE" -eq "$DATE" ]&lt;BR /&gt;   then&lt;BR /&gt;        mailx -s "Check File (`hostname`)" name.surname@company.com &amp;lt; /etc/passwd&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Best regards.&lt;BR /&gt;Ernesto</description>
      <pubDate>Thu, 20 Sep 2007 02:53:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069831#M94889</guid>
      <dc:creator>Ernesto Cappello</dc:creator>
      <dc:date>2007-09-20T02:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069832#M94890</link>
      <description>&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;CURR=`ls -l /etc/passwd`&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    PREV=CURR;&lt;BR /&gt;    sleep 1;    # check the file every second&lt;BR /&gt;    CURR=`ls -l /etc/passwd`&lt;BR /&gt;    if [ PREV != CURR]&lt;BR /&gt;    then&lt;BR /&gt;        //Send a mail (read previous reply)&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;############&lt;BR /&gt;I have not tested it, Please look for any shell specific errors.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Thu, 20 Sep 2007 03:53:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069832#M94890</guid>
      <dc:creator>Srimalik</dc:creator>
      <dc:date>2007-09-20T03:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069833#M94891</link>
      <description>Hello Sreejith,&lt;BR /&gt;&lt;BR /&gt;Here it comes,&lt;BR /&gt;&lt;BR /&gt;create a backup password file file to some where as per your choice I assume that you have /etc/paswd.old, then schedule script below in crontab as per your requirment.&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;typeset -i old_time=`ls -lc /etc/passwd.old |awk '{print $8}'|awk -F: '{print $1$2}'`&lt;BR /&gt;typeset -i new_time=`ls -lc /etc/passwd |awk '{print $8}'|awk -F: '{print $1$2}'`&lt;BR /&gt;&lt;BR /&gt;echo "Old Modication Time:" $old_time &amp;gt; tmpfile&lt;BR /&gt;echo "New Modification Time:" $new_time &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;&lt;BR /&gt;if (( $old_time != $new_time ));&lt;BR /&gt;&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt;mailx -s "password tmpfile modified" email.id@xyz.com &amp;lt; tmpfile&lt;BR /&gt;cp -p  /etc/passwd /etc/passwd.old&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Awadhesh</description>
      <pubDate>Thu, 20 Sep 2007 05:47:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069833#M94891</guid>
      <dc:creator>AwadheshPandey</dc:creator>
      <dc:date>2007-09-20T05:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069834#M94892</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;The best solution is to use Tripwire (part of Internet Express), as it is intended for this kind of thing.  Set up a "tripwire -m c" cronjob to run as often as you like.&lt;BR /&gt;&lt;BR /&gt;Or you could create a script such as the following:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;echo "Comparing /etc/passwd.1 to /etc/passwd"&lt;BR /&gt;diff /etc/passwd.1 /etc/passwd&lt;BR /&gt;echo "Moving /etc/passwd.1 to /etc/passwd.2"&lt;BR /&gt;cp /etc/passwd.1 /etc/passwd.2&lt;BR /&gt;echo "Copying /etc/passwd to /etc/passwd.1"&lt;BR /&gt;cp /etc/passwd /etc/passwd.1&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;'diff' looks at the contents of a file, not its attributes, which may or may not work for your purposes.  Schedule it to run as often as you like.&lt;BR /&gt;&lt;BR /&gt;PCS&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Sep 2007 07:56:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069834#M94892</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2007-09-20T07:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069835#M94893</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;I presume that you are using a shadow password file since otherwise normal users changing their password would update '/etc/passwd'.  That saiid, however, I'm still puzzled by your question if it is specific to the aforementioned file.  If the permissions and ownership on '/etc/passwd' are correctly restricted, only 'root' can modify it.  Thus, why would you want to montior potential changes?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 20 Sep 2007 08:05:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069835#M94893</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-20T08:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069836#M94894</link>
      <description>A thought that may/may not be worth the hassle.&lt;BR /&gt;&lt;BR /&gt;If eventually you would like to do this to support audit and monitor many other files HP IDS9000 does this on a system wide bases as well as other things.&lt;BR /&gt;&lt;BR /&gt;It is free and may be worth looking into.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Sep 2007 09:44:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069836#M94894</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2007-09-20T09:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script for file monitoring</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069837#M94895</link>
      <description>Fine Awdesh its working</description>
      <pubDate>Thu, 20 Sep 2007 23:24:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-file-monitoring/m-p/5069837#M94895</guid>
      <dc:creator>Sreejith Kumar</dc:creator>
      <dc:date>2007-09-20T23:24:37Z</dc:date>
    </item>
  </channel>
</rss>

