Linux netstat Recipe
- Create
diag_netstat.sh:#!/bin/sh OUTPUTFILE="diag_netstat_$(hostname)_$(date +"%Y%m%d_%H%M%S").log" INTERVAL="${1:-30}" # First argument or a default of 30 seconds while true; do echo "diag: $(date +"%Y%m%d %H%M%S %N %Z") iteration" >> "${OUTPUTFILE}" 2>&1 netstat -antop >> "${OUTPUTFILE}" 2>&1 sleep ${INTERVAL} done - Make it executable:
chmod +x diag_netstat.sh - Start it (default interval of 30 seconds or specify an alternate
interval as the first argument):
nohup ./diag_netstat.sh & - Reproduce the problem
- If at any point you need to reduce this disk usage of the output
file during the test, truncate the file:
cat /dev/null > diag_netstat*log
- If at any point you need to reduce this disk usage of the output
file during the test, truncate the file:
- Stop the script:
pkill -f diag_netstat - Upload
diag_netstat_*andnohup.out