Linux

Resize ext4

Online resizing just works when disk size is increased (e.g. in the cloud):

resize2fs /dev/sdb

iptables

Allow port

iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 9000 -j ACCEPT

Block port

iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 9000 -j DROP

Find IP addrs in network

nmap -sn 10.1.1.0/24 | grep 'scan report for' | awk '{print $5}' | sort -V

MD RAID

Stop RAID rebuild

echo frozen > /sys/block/md127/md/sync_action

Bash snippets

Log with datetime prefix

function log {
    echo "$(date '+%Y-%m-%d %H:%M:%S'): $@"
}
export -f log # export function for xargs

Retry function

function retry {
    local retries=5
    local timeout=30 # seconds

    local command="$@"

    local i=0

    local rc=0

    # Catch eval exit code to avoid ERR trap
    eval ${command} && rc=$? || rc=$?

    while [[ ${rc} -ne 0 && $i -lt $retries ]]; do
        log "Retry #${i} of failed command ${command}"
        sleep ${timeout}
        eval ${command} && rc=$? || rc=$?
        i=$(($i+1))
    done

    if [[ $i -eq $retries ]]; then
        log "Max retries reached for command ${command}"
        exit ${rc}
    fi
}
export -f retry # export function for xargs

Nicely print log stats with printf:

while true; do printf '%(%Y-%m-%d %H:%M:%S)T - '; grep 'error' log ; wc -l ; sleep 1 ;done

This will print something like this

2023-01-18 14:51:40 - 310
2023-01-18 14:51:41 - 410
2023-01-18 14:51:42 - 510
2023-01-18 14:51:43 - 610

storcli

Set JBOD

for d in {1..23};do storcli /c0/e17/s$d set jbod  ;done

Set UGood (from JBOD)

for d in {0..23};do storcli /c0/e17/s$d set good force  ;done

Set as hotspare

storcli /c0/e8/s13 add hotsparedrive

Show RAIDs

storcli /c0/vall show

Delete RAID

storcli /c0/v11 delete

Create 12 RAID1

for i in {0..23..2};do storcli /c0 add vd type=r1 drives=17:$i,$((i+1)) ;done