How to check if UDP port is opened on remote host

nmap -sU -p PORT IP

For example Galera requires 4567/udp port opened and I needed to check if it’s opened on one of the nodes.

root@host:~# nmap -sU -p 4567 10.10.20.20

Starting Nmap 7.01 ( https://nmap.org ) at 2018-02-04 10:04 UTC
Nmap scan report for 10.10.20.20
Host is up (0.00043s latency).
PORT STATE SERVICE
4567/udp closed unknown
MAC Address: AB:AB:AB:AB:AB:AB (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.52 seconds

Graceful view of MySQL GRANTS

Just found this script. It allows to output grants in graceful way:

mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
'SHOW GRANTS FOR \'', user, '\'@\'', host, '\';'
) AS query FROM mysql.user" | \
mysql $@ | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'

Continue reading

Oneliner to check InnoDB status in MySQL every second:

while sleep 1; do date >> /tmp/mysql_innodb_status_log && mysql -e "show engine innodb status\G;" >> /tmp/mysql_innodb_status_log; done

Simulate cron environment

Sometimes scripts aren’t working in cron, but they’re working manually. To debug them it’s helpful to simulate their running under cron environment.

add this to cron and let it to run at least once

* * * * * env > ~/cron_env

run this command to simulate environment:

env - `cat ~/cron_env` /bin/sh