Skip to content

Instantly share code, notes, and snippets.

@vikrum vikrum/oneliners.txt
Last active Mar 3, 2017

Embed
What would you like to do?
Various One Liners
# On bash + Linux
# Show TCP sockstats every 5 seconds
$ while [ : ]; do echo -n `date`; echo -n ": "; cat /proc/net/sockstat | sed 'N;s/\n/ /;' | grep TCP; sleep 5; done
# Show netstat connection state counts every 5 seconds
$ while [ : ]; do echo -n `date`; echo -n ": "; netstat -n | awk '/^tcp/ {t[$NF]++}END{for(state in t){print state, t[state]} }' | tr '\n' ' '; echo ; sleep 5; done
# Show top 25 established IPs and their counts
$ lsof -n|grep TCP|grep ESTABLISHED|awk '{print $9}' |grep -e "->"|awk -F '->' '{print $2}'|awk -F ':' '{print $1}'|sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n|uniq -c|sort -rn|head -25
# Get aggregates for drop watches (sum a column per category)
$ awk '{print $1, $4}' dropwatch |perl -e 'my %hash = (); while(<>) { chomp; ($val, $cat) = split(/ /, $_); $hash{$cat} = $hash{$cat} + $val; }; while ( my ($key, $value) = each(%hash) ) { print "$value $key\n"; } ' |sort -rn
# Show nicely formated HTTP requests with headers
$ ngrep -q -W byline "GET|PUT|POST|DELETE" port 80
# Show context switches per second
$ while [ : ]; do CURR=`cat /proc/stat |grep ctxt|awk '{print $2}'`; echo `expr $CURR - $PREV`; PREV=$CURR; sleep 1; done
# Show packets (rx & tx) per second
$ while [ : ]; do LINE=`cat /proc/net/dev|grep eth0`; CURRX=`echo $LINE | awk -F ':' '{print $2}' | awk '{print $2}'`; CURTX=`echo $LINE | awk -F ':' '{print $2}' | awk '{print $10}'`; echo RX `expr $CURRX - $PREVRX` TX `expr $CURTX - $PREVTX`; PREVRX=$CURRX; PREVTX=$CURTX; sleep 1; done
# Redirection with sudo
$ sudo bash -c "echo 1.2.3.4 example.com >> /etc/hosts"
# SSL timing and debug with cURL
$ curl -svw "\ntime_namelookup: %{time_namelookup}\ntime_connect: %{time_connect}\ntime_ssl: %{time_appconnect}\ntime_pretransfer: %{time_pretransfer}\ntime_redirect: %{time_redirect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n\n" -o /dev/null https://s-dal5-nss-5.firebaseio.com/.json
# Set difference
$ cat /usr/share/dict/words | grep -f check-words | cat check-words -|sort|uniq -c|sort -rn |grep -e " 1 "|awk '{print $2}' |grep -f - check-words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.