Archive for March, 2023
28
Mar
linux folder monitoring
yum -y install inotify-tools
[root@worker-3 ~]# cat watch.sh
#!/bin/bash
TARGET=/var/log/pods/
inotifywait -m -e create -e moved_to --format "%f" $TARGET \
| while read FILENAME
do
echo Detected path $TARGET file $FILENAME
sleep 5
SUBDIR="`ls ${TARGET}${FILENAME}`"
POD="`echo $FILENAME | cut -d'_' -f 2`"
tail -f ${TARGET}$FILENAME/$SUBDIR/0.log | logger -t "$POD" &
done
[root@worker-3 ~]# cat dwatch.sh
#!/bin/bash
TARGET=/var/log/pods/
inotifywait -m -e delete –format “%f” $TARGET \
| while read FILENAME
do
echo Deleted path $TARGET file $FILENAME
kill `ps ax | grep tail | grep $FILENAME | cut -b 1-6`
done
[root@worker-3 ~]#