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

function log {
    echo "$(date '+%Y-%m-%d %H:%M:%S'): $@"
}
export -f log # export function for xargs
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

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