#!/bin/sh if [ "$1" = "ssh" ] && [ -z "$TERM" ] ; then MESS="USER USE SSH AUTH [not console]" elif [ "$1" = "bash" ] && [ ! -z "$TERM" ] ; then if [ ! -z "$SUDO_USER" ] && [ "$TERM" = "linux" ] ; then MESS="USER USE SUDO DISPLAY CONSOLE [terminal]" elif [ ! -z "$SUDO_USER" ] && [ ! "$TERM" = "linux" ] ; then MESS="USER USE SUDO SSH CONSOLE [ssh session]" elif [ "$TERM" = "linux" ] ; then MESS="USER USE DISPLAY CONSOLE [terminal]" elif [ ! -z "$SSH_TTY" ] ; then MESS="USER USE SSH CONSOLE [ssh session]" else MESS="USER LOGGED [unknown]" fi fi if [ ! -z "$MESS" ] ; then if [ ! -z "$SSH_TTY" ] ; then M_TTY=" TTY = $SSH_TTY |" fi if [ ! -z "$SUDO_USER" ] ; then M_SUDO=" SUDO = $SUDO_USER |" fi if [ ! -z "$TERM" ] ; then M_TERM=" TERM = $TERM |" fi SEND="$MESS | USER = $USER |$M_TTY$M_SUDO$M_TERM" /sbin/telegram "$SEND" "ALERT" > /dev/null fi #!/bin/sh if [ $# -gt 0 ] then text="[$2] `cat /etc/hostname` : $1" url="https://api.telegram.org/bot{TOKEN}/sendMessage" curl \ --data-urlencode "chat_id={CHAT_ID}" \ --data-urlencode "text=$text" \ --connect-timeout 10 \ --max-time 10 \ $url > /dev/null 2>&1 else echo "Text is empty" fi /sbin/onlogged ssh ... ... /sbin/onlogged bash Source: https://habr.com/ru/post/441774/
All Articles