28
Mar

linux folder monitoring

   Posted by: admin   in Linúc ếch bợt


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 ~]#

This entry was posted on Tuesday, March 28th, 2023 at 7:04 am and is filed under Linúc ếch bợt. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed at this time.