Development Tips
Sun, Oct 23, 2016useful tips
- grep get ip addr:
shell grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"
- unique grep result:
shell grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | cut -d ' ' -f 4 | sort -u
- inotify:
install
yum --enablerepo=epel -y install inotify-tools
monitor.sh
#!/bin/bash
TARGET=$1
ACTION=$2
while inotifywait -e modify ${TARGET}; do
/bin/bash ${ACTION} ${TARGET}
done
action.sh
#!/bin/bash
#/var/log/nginx/error.log
TARGET=$1
cat ${TARGET} | grep 'limiting requests' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | cut -d ' ' -f 4 | sort -u
use it:
./monitor.sh /var/log/nginx/error.log ./action.sh