Conexão ssh ativa:
# netstat -an | grep -E "\:22[ \t]+" | grep ESTABLISHED | wc -l
1
Conexão ativa do Samba:
# netstat -an | grep -E "\:445[ \t]+" | grep ESTABLISHED | wc -l
ou use lsof:
SSHCONNECTION='lsof -i :22 | grep ESTABLISHED | wc -l'
SAMBACONNECTION='lsof -i :445 | grep ESTABLISHED | wc -l'
echo "SSH connection: ${SSHCONNECTION} Samba connection ${SAMBACONNECTION}"