1834276 Members
2522 Online
110066 Solutions
New Discussion

Script with awk

 
Rommy Setiadi_1
Occasional Contributor

Script with awk

I have list file,I want to now if 1 file on a directory was change size or date time, I get the email for this case. If the file not modified the date time or size, email not come.

Rommy Setiadi
3 REPLIES 3
Elmar P. Kolkman
Honored Contributor

Re: Script with awk

For this, you need to keep record of the last time the check command ran.

This doesn't seem like an awk script. Just from shell is good enough, I think:

#!/bin/ksh
if [ $# -ne 1 ]
then
echo "Usage: $0 "
exit 1
fi
BASE=`basename "$1"`
STAMPFILE="/var/adm/stamps/${BASE}.stamp"

if [ -f $"{STAMPFILE}" ]
then
mv "${STAMPFILE}" "${STAMPFILE}.prev"
fi

ls -l "$1" >"${STAMPFILE}"

if [ -f "${STAMPFILE}.prev" ]
then
if cmp -s "${STAMPFILE}" "${STAMPFILE}.prev"
then
echo "Files are the same"
else
echo "File changed."
echo "Was:"
cat "${STAMPFILE}.prev"
echo "Is now:"
cat "${STAMPFILE}"
fi
else
echo "First run. Nothing to compare yet."
fi
Every problem has at least one solution. Only some solutions are harder to find.
Hoefnix
Honored Contributor

Re: Script with awk

Why using awk to find changed files, you can use find to find changed files within the last 24hours.

find /path/directory -mtime 1 >/tmp/tmp.lst
if [ `cat /tmp/tmp.lst | wc -l` -gt 0 ]
then
cat /tmp/tmp.lst | mailx -s "files found" account@domain.com
fi

Jeroen Peereboom
Honored Contributor

Re: Script with awk

Another approach:

Store the output of 'ls -l'.
Net time you run 'ls -l' again, and run a diff between the two listings.
This will only tell you 'something' has changed.

If you want to keep history, use rcs to store all (different) versions.

JP