System Admin - *nix

Handy Commands / Snippets

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

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

netcat - measuring bandwidth between servers

# 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

SimpleHTTPServer — Simple HTTP request handler

SimpleHTTPServer is a core python library which provides a very easy way to set up a static HTTP server from a directory (for instance to check the local munin reports for a server which is no running it's own http server:

python -m SimpleHTTPServer

When The library is invoked using the python -m option ("run library module as a script") it binds to all network interfaces (by default on port 8000) and logs to stdout:

user@server:/var/cache/munin/www$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
10.0.10.1 - - [13/Feb/2018 22:54:47] "GET / HTTP/1.1" 200 -
10.0.10.1 - - [13/Feb/2018 22:54:47] "GET /static/style-new.css HTTP/1.1" 200 -
10.0.10.1 - - [13/Feb/2018 22:54:48] "GET /static/logo-h.png HTTP/1.1" 200 -
10.0.10.1 - - [13/Feb/2018 22:54:48] "GET /static/favicon.ico HTTP/1.1" 200 -
...

The port can be given if needed:

user@server:/var/cache/munin/www$ python -m SimpleHTTPServer 1234
Serving HTTP on 0.0.0.0 port 1234 ...
10.0.10.1 - - [13/Feb/2018 22:59:16] "GET / HTTP/1.1" 200 -
10.0.10.1 - - [13/Feb/2018 22:59:16] "GET /static/style-new.css HTTP/1.1" 200 -
10.0.10.1 - - [13/Feb/2018 22:59:17] "GET /static/logo-h.png HTTP/1.1" 200 -
10.0.10.1 - - [13/Feb/2018 22:59:17] "GET /static/favicon.ico HTTP/1.1" 200 -
...

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.

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

External References

BradsWiki: System Admin/nix (last edited 2018-02-13 23:00:39 by BradleyDean)