In my directory, I have a text file called test.txt
and I have a shell script called targetscript.sh
.
I want to run this shell script when any changes occur on test.file. On my server, I have no option to install new tools like inotfy
or similar like anything.
So after some research I wrote the following shell script which will take the time stamp of test.txt and if any changes occur it will trigger the targetscript.sh
.
#!/bin/bash
while true
do
ATIME=$(stat -c %Z /home/haider/test.txt)
if [[ "$ATIME" != "$LTIME" ]]; then
echo "RUN COMMNAD"
./targetscript.sh
LTIME=$ATIME
fi
sleep 5
done