Skip to content

Instantly share code, notes, and snippets.

@mikaelkall

mikaelkall/sysadmin.md

Last active Oct 16, 2020
Embed
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 10.0.1.1 netmask 255.255.255.252   
cli># ifconfig tun5 10.0.1.2 netmask 255.255.255.252   

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 TCP:nighter.se:80

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.