Pular para o conteúdo

Ajudem com o script [RESOLVIDO]

Responder tópico
  • Denunciar
  • Indicar

1. Ajudem com o script [RESOLVIDO]

Enviado em 10/10/2016 - 20:22h

Fiz um script mais to com dificuldade, ele está funciona no normalmente mais quando executo ele as linhas de número de usuário ficam desorganizadas.
Script
#!/bin/sh
lsusers="/tmp/users"
echo $$ > /tmp/pid
if [ ! -f "$lsusers" ]
then
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
fi
while true
do
tput setaf 6; echo "\nUsuário Nº de Conexões\n" ; tput sgr0
while read lnusers
do
user="$(echo $lnusers | cut -d' ' -f1)"
ps x | grep $user | grep -v grep | grep -v pts > /tmp/tmp.tmp
conexoes="$(cat /tmp/tmp.tmp | wc -l)"
echo "$user $conexoes"
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
done < "$lsusers"
echo " "
exit 1
done
Se tiver com dificuldade de entender o script aí o link
http://pastebin.com/raw/M7uBErRp

Imagem de como fica
https://postimg.org/image/tu5l8huix/

Quero deixa ele assim se alguém pode ajuda
https://postimg.org/image/lslmjjyl1/

Responder tópico

2. Re: Ajudem com o script [RESOLVIDO]

Melhor resposta

Enviado em 10/10/2016 - 23:15h

Tem sim:

#!/bin/sh

bg_red="$(tput setab 1)"
bg_clr="$(tput setab 0)"

lsusers="/tmp/users"
echo $$ > /tmp/pid

if [ ! -f "$lsusers" ]
then
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
fi

while true; do
echo -ne ${bg_red}" SSH Monitor "
tput setaf 7; echo -ne "\n Usuário\t Nº de Conexões${bg_clr}\n\n" | expand -t 20 ; tput sgr0
while read lnusers; do
user="$(echo $lnusers | cut -d' ' -f1)"
ps x | grep $user | grep -v grep | grep -v pts > /tmp/tmp.tmp
conexoes="$(cat /tmp/tmp.tmp | wc -l)"
tput setaf 3; echo -e " $user\t $conexoes" | expand -t 19; tput sgr0
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
done < "$lsusers"
echo
exit 0
done
______________________________________________________________________
OS: Kali Linux kali-rolling kali-rolling
Kernel: x86_64 Linux 4.6.0-kali1-amd64
Resolution: 2390x768
CPU: Intel Core i3-4005U CPU @ 1.7GHz
RAM: 3852MiB

3. Re: Ajudem com o script [RESOLVIDO]

Enviado em 10/10/2016 - 20:50h

é só usar o expand com a opção -t para concertar tudo, teste ai:

#!/bin/sh

lsusers="/tmp/users"
echo $$ > /tmp/pid

if [ ! -f "$lsusers" ]
then
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
fi

while true; do
echo -e "\tSSH Monitor"
tput setaf 6; echo -e "\nUsuário\tNº de Conexões\n" | expand -t 20 ; tput sgr0
while read lnusers
do
user="$(echo $lnusers | cut -d' ' -f1)"
ps x | grep $user | grep -v grep | grep -v pts > /tmp/tmp.tmp
conexoes="$(cat /tmp/tmp.tmp | wc -l)"
echo -e "$user\t$conexoes" | expand -t 19
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
done < "$lsusers"
echo " "
exit 1
done
______________________________________________________________________
OS: Kali Linux kali-rolling kali-rolling
Kernel: x86_64 Linux 4.6.0-kali1-amd64
Resolution: 2390x768
CPU: Intel Core i3-4005U CPU @ 1.7GHz
RAM: 3852MiB

4. Re: Ajudem com o script

Enviado em 10/10/2016 - 22:09h

Conseguir dessa forma como você disse só organizei algumas coisas pq ele estava ficando com -e na fresta dos ssh mais consegue arrumar
#!/bin/sh

lsusers="/tmp/users"
echo $$ > /tmp/pid

if [ ! -f "$lsusers" ]
then
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
fi

while true; do
echo "\tSSH Monitor"
tput setaf 6; echo "\nUsuário\tNº de Conexões\n" | expand -t 20 ; tput sgr0
while read lnusers
do
user="$(echo $lnusers | cut -d' ' -f1)"
ps x | grep $user | grep -v grep | grep -v pts > /tmp/tmp.tmp
conexoes="$(cat /tmp/tmp.tmp | wc -l)"
echo "$user\t$conexoes" | expand -t 19
awk -F : '$3 >= 500 { print $1 "" }' /etc/passwd | grep -v '^nobody' > /tmp/users
done < "$lsusers"
echo " "
exit 1
done
Queria sabe se tem como eu deixa o monitor dessa forma tbm
https://postimg.org/image/lslmjjyl1/

5. Re: Ajudem com o script [RESOLVIDO]

Enviado em 11/10/2016 - 08:14h

Obrigado pela ajuda, consegue aqui

Responder tópico

Responder tópico

Entre na sua conta para responder.

Fazer login para responder