System Admin - *nix

Handy Commands / Snippets

trafshow

trafshow is an interactive text-based program that allows network connections to be monitored, somewhat like using netstat and tcpdump but using arrows and the enter key instead of typing stuff in. Available in the netdiag debian package.

mtr

mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool. Available in the mtr and mtr-tiny debian packages. mtr includes gtk wheras mtr-tiny does not so it comes which much fewer package dependencies.
A handy command to build a report:

mtr -r -w -c 10 example.net

column

column makes it easy to format data into visually spaced columns. For instance:

( x=0; while [ $x -lt 20 ] ; do echo $RANDOM $RANDOM   $RANDOM  $RANDOM $RANDOM        $RANDOM; x=$(($x+1)); done ) | column -t

It's also possible to use a different input delimiter:

( x=0; while [ $x -lt 20 ] ; do echo ${RANDOM}z${RANDOM}z${RANDOM}zzz${RANDOM}z${RANDOM}z${RANDOM}; x=$(($x+1)); done ) | column -t -sz

zdump

zdump prints the current time in each zonename named on the command line, and also dumps out all timezone transitions:

# Check the timezone changes configured on a system in Melbourne for 2016:
$ zdump -v /usr/share/zoneinfo/Australia/Melbourne | grep 2016
/usr/share/zoneinfo/Australia/Melbourne  Sat Apr  2 15:59:59 2016 UTC = Sun Apr  3 02:59:59 2016 EST isdst=1 gmtoff=39600
/usr/share/zoneinfo/Australia/Melbourne  Sat Apr  2 16:00:00 2016 UTC = Sun Apr  3 02:00:00 2016 EST isdst=0 gmtoff=36000
/usr/share/zoneinfo/Australia/Melbourne  Sat Oct  1 15:59:59 2016 UTC = Sun Oct  2 01:59:59 2016 EST isdst=0 gmtoff=36000
/usr/share/zoneinfo/Australia/Melbourne  Sat Oct  1 16:00:00 2016 UTC = Sun Oct  2 03:00:00 2016 EST isdst=1 gmtoff=39600

# Check the current time in a couple of different timezones:
$ zdump /usr/share/zoneinfo/Australia/Melbourne /usr/share/zoneinfo/Europe/London 
/usr/share/zoneinfo/Australia/Melbourne  Tue May  3 14:39:25 2016 EST
/usr/share/zoneinfo/Europe/London        Tue May  3 05:39:25 2016 BST

measuring bandwidth between servers using netcat

# Run both ways, a number of times for confirmation
# Imagine serverA and serverB:

# set up netcat to listen (write the output into wc to confirm the bytes expected are received)
serverA$ nc -l -p 12345 | wc -c

# On serverA send a bunch of data (in this case 1GiB) using netcat - use "-q 0" to force a quit as soon as EOF is reached:
serverB$ dd if=/dev/zero bs=$((2**20)) count=$((2**10)) | nc -q 0 serverA 12345

# On each server the output will look something like:

# serverA:
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 9.68678 s, 111 MB/s

# serverB:
$ nc -l -p 12345 | wc -c
1073741824

External References

BradsWiki: System Admin/nix (last edited 2017-03-14 23:51:16 by BradleyDean)