Givaldodionizio
(usa Ubuntu)
Enviado em 13/06/2018 - 15:58h
boa tarde!!
com esse script monitoro os usuário online e off no meu servidor mas queria fazer uma linha com o total on e total off alguém sabe como fazer??
abaixo o script q uso.
#!/bin/bash
function CTRL()
{
h
exit
}
trap CTRL SIGINT
DATABASE="/home/DATABASE/users.db"
while true; do
clear
echo ""
echo -ne " \033[01;37;44m"; printf '%38s%-28s\n' "MONITORING"; echo -ne "\033[0m"
echo -e " \033[01;37;44m USUÁRIO SSH/VPN UPTIME STATUS \033[0m"
echo ""
cat $DATABASE | sort | while read DB; do
DB1=$(echo $DB | cut -d " " -f1)
DB2=$(ps -u $DB1 | grep sshd | wc -l)
DB4=$(cat /etc/openvpn/openvpn-status.log | cut -d " " -f1 | grep "$DB1" | cut -d "," -f1 | grep "$DB1" | wc -l)
DB3=$(echo $DB | cut -d " " -f3)
NUMBER1=$(ps -u $DB1 | grep sshd | wc -l)
NUMBER2=$(cat /etc/openvpn/openvpn-status.log | grep -E ,"$DB1", | wc -l)
if [ $NUMBER1 -gt 0 ]; then
PID=$(ps -u $DB1 | grep sshd | awk -F " " '{print $1 }')
UPTIME=$(ps -o etime $PID | sed -n '2p' | awk -F " " '{print $1}')
echo -ne " \033[01;32m"; printf '%-24s%-17s%-18s%s\n' " $DB1" "$DB2/$DB4" "$UPTIME" "Online"
elif [ $NUMBER2 -gt 0 ]; then
echo -ne " \033[01;32m"; printf '%-24s%-17s%-19s%s\n' " $DB1" "$DB2/$DB4" "INDISPONÍVEL" "Online"
else
echo -ne " \033[01;31m"; printf '%-24s%-17s%-18s%s\n' " $DB1" "0/0" "00:00" "Offline"
fi
echo -e "\033[01;30m =================================================================="
done
echo ""
echo -e "\033[01;36m APERTE CTRL+C PARA VOLTAR AO MENU..."
sleep 10s
done