Hi,
I need to run a script file which uses a file and that file is modified as and when some alarms generated, it is not based on any fixed time period.. it may be modified even once in a minute for some time and once in 30 min or once in 20 min. Hence i need to watch for the timestamp change of this file and run some scripts to process that. Since the file is overwritten i have to follow this kind of process.
pls guide me..
---------- Post updated at 05:44 PM ---------- Previous update was at 05:35 PM ----------
Hope this may help
time=$(ls -l $1 | awk -F" " '{ print $7 }')
while :
do
chk_time=$(ls -l $1 | awk -F" " '{ print $7 }')
if [ "$chk_time" != "$time" ]
then
echo "File modified"
mailx -s "File $1 modified" abc.dfg@xxx.com
break; # if you want to stop the script once mail is send
fi
sleep 5 # 5sec wait time
done
so what is it that you want?
regards,
Ahamed
Hi,
In a hurry i posted that requirement and searched immediately and got some clue...but i tried the following way i could not succeed.
#!/bin/bash
time=$(ls -l /home/dg/sm.ini | /usr/xpg4/bin/awk -F" " '{ print $8 }')
timehr=$(echo $time | /usr/xpg4/bin/awk -F: '{print $1}')
timemin=$(echo $time | /usr/xpg4/bin/awk -F: '{print $2}')
while :
do
chk_time=$(ls -l /home/dg/sm.ini | /usr/xpg4/bin/awk -F" " '{ print $8 }')
chk_timehr=$(echo $chk_time | /usr/xpg4/bin/awk -F: '{print $1}')
chk_timemin=$(echo $chk_time | /usr/xpg4/bin/awk -F: '{print $2}')
if [ "$chk_timehr" != "$timehr" ] && [ "$chk_timemin" != "$timemin" ]
then
echo "/home/dg/SM/SMfile"
sleep 5
echo "/home/dg/SM/SMomAlarm"
fi
sleep 5 # 5sec wait time
done
pls help me
Try this
#!/bin/bash
while :
do
chk_time=$(ls -l run | awk -F" " '{ print $8 }')
chk_timehr=$(echo $chk_time | awk -F: '{print $1}')
chk_timemin=$(echo $chk_time | awk -F: '{print $2}')
if [ "$chk_timehr" != "$timehr" ] || [ "$chk_timemin" != "$timemin" ]
then
time=$(ls -l run | awk -F" " '{ print $8 }')
timehr=$(echo $time | awk -F: '{print $1}')
timemin=$(echo $time | awk -F: '{print $2}')
echo "/home/dg/SM/SMfile"
sleep 5
echo "/home/dg/SM/SMomAlarm"
fi
sleep 5 # 5sec wait time
done
regards,
Ahamed