ស្វែងយល់ពី Tracking File Change នៅក្នុងលីនុច

Words
127
Reading
1 min
Listen
Play
9y

inotify.png

Inotify ជា Tool មួយដែលត្រូវបានគេប្រើប្រាស់នៅក្នុងលីនុចដើម្បីអោយដឹងថា តើ File ណាមួយត្រូវបានផ្លាស់ប្តូ តើមានការលុបឬកែប្រែFileអ្វីមួយឬទេ?

Inotify ជា Service មួយសម្រាប់ ត្រួតពិនិត្យលើ Linux File System មិនមែនដូច Samba Server ប្រើប្រាស់ Service ផ្សេងមួយទៀតដែលឈរលើ Linux File System នោះទេ។ដូចនេះ inotify វាស្ថិតនៅស្រទាប់ក្រោម Samba Server និង NFS Server

ការប្រើប្រាស់ និងតម្លើងមិនមានការពិបាកនោះទេដោយគ្រាន់តែដោនឡូតចេញពី repository EPEL

yum install inotify-tools

បន្ទាប់មកទៀតអាចសាកល្បងធ្វើតេសន៍បានថាតើវាពិតជាដំណើរការឬទេ?

inotifywait -e create,delete,modify,move -mrq /etc &

inotify (1).png

ចំពោះការប្រើប្រាស់ command បែបនេះវាមិនស្ថិតស្ថេរនោះទេនៅពេលដែលបិទ Server វានិងឈប់ Monitor ដូចនេះខាងក្រោមនេះជាការបង្កើត Script មួយដើម្បីអោយវាអាចដំណើរការជា Service បាន។

ដំបូងត្រូវបង្កើត Configuration File មួយជាមុនសិន ដោយបង្កើត File ថ្មីមួយឈ្មោះថា inotifywait.conf នៅក្នុង

vi /etc/inotifywait.conf

create1.png

ជំហ៊ានបន្ទាប់ត្រូវបង្កើត Service នៅក្នុង vi /etc/rc.d/init.d/inotifywait ដោយសរសេរដូចខាងក្រោមនេះ

. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
. /etc/inotifywait.conf

LOCK=/var/lock/subsys/inotifywait

RETVAL=0
start() {
echo -n $Starting inotifywait: 
/usr/bin/inotifywait \
format %w%f %e %T \
timefmt %Y/%m/%d-%H:%M:%S \
exclude .*\.sw[pox].* \
-e $EVENT \
-o $LOGFILE \
-dmrq $MONITOR

RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCK
return $RETVAL
}
stop() {
echo -n $Stopping inotifywait: 
killproc inotifywait
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCK
return $RETVAL
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status inotifywait
;;
restart)
stop
start
;;
*)
echo $Usage: $0 {start|stop|status|restart}
exit 1
esac
exit $?

បន្ទាប់ពីចប់សព្វគ្រប់ហើយអាច Restart Service បាន

systemctl restart inotifywait

រូបភាពខាងក្រោមនេះជាការ Send Report អោយទៅជា html file ដើម្បីងាយស្រួល Access ចូលមើលតាមរយះ web browser

ដោយគ្រាន់តែ Configure LOGFILE=/var/www/html/inotify.html នោះ inotify និងបោះពត៏មានទៅកាន់ File html តែកុំភ្លេចប្តូ Permission អោយទៅ 777 ទាំងអស់ដើម្បីអោយ inotify អាច write ចូលទៅកាន់ File html បាន។

នៅពេលដែលដំណើរការបានជោគជ័យអាចមើលរូបខាងក្រោម

easy.png

ការលុប File នៅក្នុង Command និង Report នៅក្នុងhtml file ដូចគ្នា បញ្ជាក់ថា Inotify ដំណើរការបានត្រឹមត្រូវ។

Inotify ប្រសិនបើប្រើប្រាស់ដើម្បី Monitor ទៅលើ Samba VFS វានិងបញ្ហាញថា File ដែលបានលុបដោយ samba user គ្រាន់តែជាការ Move ទៅកាន់ Directory ផ្សេងតែប៉ុណ្ណោះ។

ប្រភពដើម

ស្វែងយល់ពី Tracking File Change នៅក្នុងលីនុច | Ecency