วันศุกร์ที่ 31 มีนาคม พ.ศ. 2560

ทำระบบ Notify ง่ายๆ ผ่าน Line API แจ้งเมื่อมีคน login (SSH) เข้า server เรา Linux

nano /root/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

servIP=`ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*'`
REMOTE_USER=`whoami`
REMOTE_IP=`who am i`
CUTIP=${REMOTE_IP%)*}
CUTIP=${CUTIP##*(}

curl -X POST -H 'Authorization: Bearer {LineTOken}' -F 'message=Server "'"$servIP"'"
have SSH login via IP "'"$CUTIP"'" by user "'"$REMOTE_USER"'"
 ' https://notify-api.line.me/api/notify

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

unset USERNAME