Diferencia entre revisiones de «One-liners»

De Wiki Técnico Rioja. Administra tus sistemas.
Sin resumen de edición
 
(No se muestran 10 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
[[Categoría: Linux]]
[[Categoría: Linux]]
=== Apache===
=== '''Apache'''===
'''Este solo dominios:'''
<pre>tail -n 5000 /srv/log/httpd/access_log | awk '{print $1}' | sort | uniq -c |sort -n | tail</pre>


===Postfix ( envios )===
'''Este es para las ip: nos saca las IP que le estan dando cera a la maquina'''
 
<pre>tail -n 5000 /srv/log/httpd/access_log | awk '{print $2}' | sort | uniq -c |sort -n | tail</pre>
 
'''Este te muestra ip y dominio:'''
<pre>tail -n 5000 /srv/log/httpd/access_log | awk '{print $1, $2}' | sort | uniq -c |sort -n | tail</pre>
 
'''Conexiones'''
 
<pre>netstat -putan | egrep ':80|:443' | sort -k5</pre>
 
<pre>netstat -tlna | egrep "(:80|:443)" | awk '{print $5}' | cut -d ":" -f 1 | sort | uniq -c | sort -n</pre>
 
<pre>watch  "netstat -ntlpa | egrep ':80|:443' | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n| tail -n 20"</pre>
 
'''Pseudotop con CPU solo de los procesos php'''
 
<pre>watch "ps -eo pid,user,%cpu,%mem,command --sort=-%cpu | grep '[p]hp-fpm'"</pre>
'''Conexiones a puertos 80|443'''
<pre>netstat -tlna | egrep ":80|:443" | awk {'print $5'} | cut -d ':' -f 1 | sort | uniq -c | sort -n | tail</pre>
 
'''Ataque a xmlrpc.php'''
 
<pre>cat  /srv/log/httpd/access_log | awk '{print $1" " $2 " " $8}' | grep xmlrpc.php | sort | uniq -c |sort -n | tail</pre>
 
'''Buscar errores 404|403'''
 
<pre>cat /srv/log/httpd/access_log | grep -E 'HTTP/2.0" (403|404)' | awk '{print $1, $2, $8, $10}' | sort | uniq -c | sort -n | tail -n 50</pre>
 
'''Reiniciar Apache + php-fpm + xymon'''
 
<pre> systemctl restart php* httpd xymon </pre>


===Mysql===
===Mysql===


===Autenticaciones ===
'''Ver procesos interactivamente.'''
 
<pre>watch -d -n0.5 'mysql -e "show processlist;" |grep -v Sleep | sort -k2'</pre>
 
'''Ver conexiones ( ips origen )'''
 
<pre>watch  "netstat -ntlpa | grep ':3306' | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n| tail -n 20"</pre>
 


Ver intentos de login a tu servidor via SSH:
'''Matar procesos de mas de 100 segundos'''


<pre>
<pre>mysql -e 'SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST where time>100 ' | grep -v scheduler | awk '{print "kill "$1";"}'|grep -v ID |mysql</pre>
journalctl --since "24 hour ago" | grep -i "Failed password for invalid user" | awk '{print $13}' | sort -n | uniq  </pre>


o
'''Matar procesos de una BBDD'''


<pre> journalctl --since "24 hour ago" | grep -i "Failed password for root " | awk '{print $11}' | sort -n | uniq </pre>
<pre>mysql -e "show full processlist" | grep qaeo957  | awk '{print "mysql -e \"kill " $1 "\""}' | sh</pre>

Revisión actual - 11:50 30 ene 2025

Apache

Este solo dominios:

tail -n 5000 /srv/log/httpd/access_log | awk '{print $1}' | sort | uniq -c |sort -n | tail

Este es para las ip: nos saca las IP que le estan dando cera a la maquina

tail -n 5000 /srv/log/httpd/access_log | awk '{print $2}' | sort | uniq -c |sort -n | tail

Este te muestra ip y dominio:

tail -n 5000 /srv/log/httpd/access_log | awk '{print $1, $2}' | sort | uniq -c |sort -n | tail

Conexiones

netstat -putan | egrep ':80|:443' | sort -k5
netstat -tlna | egrep "(:80|:443)" | awk '{print $5}' | cut -d ":" -f 1 | sort | uniq -c | sort -n
watch  "netstat -ntlpa | egrep ':80|:443' | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n| tail -n 20"

Pseudotop con CPU solo de los procesos php

watch "ps -eo pid,user,%cpu,%mem,command --sort=-%cpu | grep '[p]hp-fpm'"

Conexiones a puertos 80|443

netstat -tlna | egrep ":80|:443" | awk {'print $5'} | cut -d ':' -f 1 | sort | uniq -c | sort -n | tail

Ataque a xmlrpc.php

cat  /srv/log/httpd/access_log | awk '{print $1" " $2 " " $8}' | grep xmlrpc.php | sort | uniq -c |sort -n | tail

Buscar errores 404|403

cat /srv/log/httpd/access_log | grep -E 'HTTP/2.0" (403|404)' | awk '{print $1, $2, $8, $10}' | sort | uniq -c | sort -n | tail -n 50

Reiniciar Apache + php-fpm + xymon

 systemctl restart php* httpd xymon 

Mysql

Ver procesos interactivamente.

watch -d -n0.5 'mysql -e "show processlist;" |grep -v Sleep | sort -k2'

Ver conexiones ( ips origen )

watch  "netstat -ntlpa | grep ':3306' | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n| tail -n 20"


Matar procesos de mas de 100 segundos

mysql -e 'SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST where time>100 ' | grep -v scheduler | awk '{print "kill "$1";"}'|grep -v ID |mysql

Matar procesos de una BBDD

mysql -e "show full processlist" | grep qaeo957  | awk '{print "mysql -e \"kill " $1 "\""}' | sh