You have either the choice that a script/program is running all the time and scanning that dir to inform you or maybe a cronjob running "only" every minute and checking let's say with something like:
TMP_FILE="/tmp/last_num_of_files.tmp"
NUM_BEFORE=`cat ${TMP_FILE}`
NUM_NOW=`ls -1 /somedir/*xml| wc -l | awk '{print $1}'`
if (( ${NUM_NOW} > ${NUM_BEFORE} )); then
echo "Hey, it changed!"| mail -s "New files arrived" me@server.org"
fi
echo ${NUM_NOW} > ${TMP_FILE}
exit 0
I am not sure about this terminology. I am new to UNIX.
I will explain what i am trying to do.
1) I want to keep track of all files which are getting created or coming from different server in a particular directory.
2) I want to store attributes of all files in different file.
e.g.
Suppose following files came to unix directory:
-rw-rw---- 1 rasadm unixadmin 12 Oct 06 08:19 file0.dat
-rw-rw---- 1 rasadm unixadmin 697 Oct 06 10:11 file1.dat
-rw-rw---- 1 rasadm unixadmin 505 Oct 06 10:11 file2.dat
Now,
When file0.dat is coming at 08:19 AM --
system should automatically detect the presence of new file and should add attributes of it ( Like timestamp, size ) to new file say filelog.dat.
When file1.dat and file2.dat are coming at 10:11 AM --
system should automatically detect the presence of new files and should add attributes of it ( Like timestamp, size ) to filelog.dat.
# File_list contains a file name of latest file processed when script ran the last time.
last_file=`cat $file_list`
find <directory where new files arrive> -newer $last_file
# Above command will give you list of all the new files arrived after $last_file
So, assume new files come in /etc then you will do the following:
last_file=`cat $file_list`
for a in `find /etc -newer $last_file`
do
ls -l $a >> logfile # Use cut or awk to just output selected attributes
done
echo $a > $file_list