Skip to content

Instantly share code, notes, and snippets.

@o0-o
o0-o / ssh_key_create.sh
Last active May 7, 2019 02:27
[Create SSH Key] Generate and install an SSH key #Shell
# ssh_key_create.sh
#
# parameter: user@host
# example: [email protected]
( # try ed25519
( ssh-keygen -t ed25519 -b 4096 -f "~/.ssh/$1" &&
ssh-copy-id -i ~/.ssh/"$1" "$1"
) ||
@o0-o
o0-o / bash_version.sh
Last active May 7, 2019 02:27
[Bash Version] Prints the version of bash that is locally installed #Shell
# bash_version.sh
( bash --version |
grep --only-matching --max-count=1 "([0-9]*\.){2}[0-9]*" |
head -n 1 #`head --lines=` isn't portable, so `-n` is used
) 2>/dev/null ||
exit 1 #failure
@o0-o
o0-o / serial.sh
Last active May 10, 2019 18:04
[Serial Number] Retrieves the serial number of the host (if one exists) #Shell
# serial.sh
( # edgeos
show version |
grep "HW S/N:" ||
# linux/bsd x86
dmidecode --string system-serial-number ||
# macos
@o0-o
o0-o / cpu_threads.sh
Last active May 7, 2019 02:30
[Number Threads] Prints the number of processing threads #Shell
# cpu_threads.sh
( # linux
getconf _NPROCESSORS_ONLN ||
# bsd
sysctl -n hw.ncpu
) 2>/dev/null ||
@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: " |
@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 / 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 / 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 / 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 / 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 ) |