Skip to content

Instantly share code, notes, and snippets.



Last active Oct 16, 2020
What would you like to do?
Documents good sysadmin solutions and oneliners to problems.

Create point to point tunnel between two servers over ssh with a tun interface to avoid the need to open a firewall.

cli># ssh -w5:5 root@hserver
srv># ifconfig tun5 netmask   
cli># ifconfig tun5 netmask   

Oneliner to list block percentage on a filesystem

dumpe2fs -h /dev/sda1 2> /dev/null | awk -F ':' '{ if($1 == "Reserved block count") { rescnt=$2 } } { if($1 == "Block count") { blkcnt=$2 } } END { print "Reserved blocks: "(rescnt/blkcnt)*100"%" }'

Set block percentage

tune2fs -m1 /dev/sda1

Write line number and function name when debug bash script.

export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
$ bash -x ./script

Run command as a service

$ socat TCP-LISTEN:6666,fork,reuseaddr exec:/command

Forward port to a different port.

socat TCP-LISTEN:9999,reuseaddr,fork,su=nobody

socat TCP-LISTEN:80,fork TCP:<address>:80

Log everything from terminal to file

exec >> /var/log/logfile 2>&1

Clone driver over ssh and create virtualbox image.

 ssh root@host "dd if=/dev/sda | gzip -1 -" | dd of=image.gz status=progress    
 gunzip image.gz
 VBoxManage convertfromraw image.bin image.vdi --format VDI
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.