bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

Using tcpdump with port ranges and file count/size

sudo /usr/sbin/tcpdump -i any -s 0 -n -Z someuser -C 500 -W 100 -w /home/someuser/$(hostname).pcap -f '(port (80 or 8080) or portrange 21-22)' &>/dev/null

March 15, 2019peek2much3

List top 10 IP addresses connected to your server on port 80 with the number of connections

netstat -tn 2>/dev/null | awk '/:80\>/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

September 26, 2018Goeks1

Display the number of connections per IP to port 80

while true; do clear; date; echo; echo "[Count] | [IP ADDR]"; echo "-------------------"; netstat -n | grep ':80\>' | awk '! /LISTEN/ {print $5}' | cut -d: -f1 | uniq -c; sleep 5; done

April 9, 2014cesp

Alert me by email when a disconnected or unreachable server comes back online

while ! ping -c1 the_host_down; do sleep 1; done && date | mail -s 'the host is back!' me@example.com

October 10, 2011janos