Skip to content

Instantly share code, notes, and snippets.

@o0-o
o0-o / password.sh
Last active May 7, 2019 02:29
[Generate Password] Generate a long random password #Shell
# password.sh
declare -r length=$(($(($RANDOM%17))+23)) 2>/dev/null && #23-39
( #openssl
openssl rand -base64 "${length-32}" ||
#os random
base64 < /dev/urandom |
fold --width="${length-32}" |
@o0-o
o0-o / uuid.sh
Last active May 7, 2019 02:30
[UUID] Prints a randomly generated UUID #Shell
# uuid.sh
uuidgen 2>/dev/null ||
exit 1 #fail
exit 0 #success
@o0-o
o0-o / net_mac_addresses.sh
Last active September 7, 2023 20:02
[MAC Addresses] Prints MAC addresses #Shell
# net_mac_addresses.sh
( # linux (NetworkManager)
nmcli -terse -fields GENERAL.HWADDR device show ||
# macos
networksetup -listallhardwareports ||
# linux/bsd
( ip address || ifconfig ) |
@o0-o
o0-o / net_if.sh
Last active May 7, 2019 02:31
[Network Interfaces] Prints network interfaces #Shell
# net_if.sh
( # linux
file /sys/class/net/* |
sed 's/.*\///g' ||
# macos
networksetup -listallhardwareports |
grep "Device:" |
awk '{ print $2 }' ||
@o0-o
o0-o / net_ip4.sh
Last active May 7, 2019 02:31
[IPv4 Addresses] Prints IPv4 addresses of the host #Shell
# net_ip4.sh
( # linux (NetworkManager)
nmcli -terse -mode tabular -fields IP4.ADDRESS device show ||
# linux (iproute2)
ip -family inet -brief address |
# linux/bsd
( ip address || ifconfig ) |
@o0-o
o0-o / math_round.sh
Last active November 22, 2021 17:12
[Round Number] Prints integer with rounding #Shell
# math_round.sh
#
# parameter: number (float)
# example: 3.14
( echo "$1" |
awk '{
x=$1
ival = int(x) # integer part, int() truncates
# see if fractional part
@o0-o
o0-o / mem.sh
Last active May 7, 2019 02:31
[Memory] Prints amount of memory in bytes #Shell
# mem.sh
( # linux
grep "MemTotal" /proc/meminfo |
awk '{ printf "%d\n", $2 * 1000 }' ||
# bsd
sysctl -n hw.realmem 2>/dev/null ||
# macos
@o0-o
o0-o / host_name.sh
Last active May 7, 2019 02:32
[Hostname] Prints hostname #Shell
# host_name.sh
hostname 2>/dev/null ||
exit 1 #failure
exit 0 #success
@o0-o
o0-o / cpu_aes.sh
Last active May 7, 2019 02:29
[CPU AES Support] Exit code reflects AES support #Shell
# cpu_aes.sh
( # linux
lscpu |
grep --quiet "aes" ||
# bsd
sysctl dev. |
grep --quiet "aes" ||
@o0-o
o0-o / disks.sh
Last active May 7, 2019 02:29
[Disks] Prints disks #Shell
# disks.sh
( # linux
lsblk --all --noheadings --list --output NAME,TYPE |
grep disk |
sed 's/[[:space:]]disk//g' ||
# bsd
geom disk list |
grep "Geom name: " |