Skip to content

Instantly share code, notes, and snippets.

View traek's full-sized avatar

Traek Malan traek

View GitHub Profile
@traek
traek / formatSeconds.ksh
Created November 8, 2023 17:31
Korn Shell script to convert seconds to human readable duration
#!/bin/ksh93
# Set variables for conversion from number of seconds
typeset -i minute=60 hour=$minute*60 day=$hour*24 week=$day*7
# Test value (integer in seconds) passed to script
if [ $1 -ge $week ]; then
printf "%dw:%dd:%02dh:%02dm:%02ds" $(($1/$week)) $(($1%$week/$day)) $(($1%$day/$hour)) $(($1%$hour/$minute)) $(($1%$minute))
elif [ $1 -ge $day ]; then
printf "%dd:%02dh:%02dm:%02ds" $(($1/$day)) $(($1%$day/$hour)) $(($1%$hour/$minute)) $(($1%$minute))
@traek
traek / syncfiles.sh
Last active May 20, 2024 14:26
Simple script to download files from single web page
#!/usr/bin/env bash
if (( $# > 0 )); then destination=$1; else destination="."; fi
# Check for required commands
required=(awk grep lynx wget); missing=()
for command in ${required[@]}; do
hash $command 2>/dev/null || missing+=($command)
done
if (( ${#missing[@]} > 0 )); then
echo "[FATAL] could not find command(s): ${missing[@]}. Exiting!"
exit 1
@traek
traek / jsh.csh
Created March 4, 2019 02:04
Enter jail shell by jail name in FreeNAS 11.2
#!/bin/csh -f
set id = `jls | grep $1 | awk '{print $1;}'`
jexec $id csh