Skip to content

Instantly share code, notes, and snippets.

View olomor's full-sized avatar

Romolo olomor

  • Brazil / São Paulo
View GitHub Profile
@olomor
olomor / sshMenuFromEtcHosts.sh
Created January 20, 2023 05:11
Generates a option menu from the list of entries at "/etc/hosts" then starts a ssh connection command for selected item number.
#!/bin/bash
export PATH=/bin:/sbin:/usr/local/bin:/usr/local/sbin
while read -a E
do
IPADDRESS_LIST=( ${IPADDRESS_LIST[@]} "${E[0]}" )
HOSTNAME_LIST=( ${HOSTNAME_LIST[@]} "${E[1]}" )
done < <(egrep -v "^127.0.0.1|^::1" /etc/hosts |sort -k2 -k1)
unset E
@olomor
olomor / broadcastHostname.sh
Last active January 20, 2023 04:21
Scripts to mantain a local host list (/etc/hosts) updated with all servers IPs at the same network, using a broadcast message containg "hostname and ip" over UDP:15000.
# =========================
# SUBSCRIBER
# =========================
cat << 'EOF' >/usr/local/sbin/broadcastHostnameSubscriber.sh
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
sleep $((RANDOM%15))
for IP_ADDRESS in $(ip address show up |grep -E 'inet [0-9]' |grep -v '127.0.0.1' |sed -r 's:(^.*inet )([0-9].*)(/.*):\2:g')
do
@olomor
olomor / _cidr.sh
Last active December 30, 2022 02:07
function bin2dec()
{
echo -n $((2#${1}))
}
function dec2bin()
{
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
echo -n ${D2B[${1}]}
@olomor
olomor / rclone.wrapper
Created February 12, 2022 06:36
rclone tool wrapper script to auto-mount and control the cloud disk at graphical user logon using systemd.
#!/bin/bash
# rclone.wrapper
Arg1=${1}
Arg2=${2}
export PATH=/usr/local/bin:/usr/bin
help()
{
cat << EOF | more
@olomor
olomor / sslTextFromShell.sh
Created May 19, 2020 00:31
A simple "vault" option to store encrypted texts (using openssl lib) on any public document.
sslTextEnc () { sslTextPwd ; read -p "Texto a cryptografar: " TEXT; echo "TEXT" | openssl aes-256-cbc -e -a -iter 2 -pass env:SSLPASS 2>/dev/null; unset SSLPASS; }
sslTextDec () { sslTextPwd ; read -p "Texto a des-cryptografar: " TEXT; echo "${@}" | openssl aes-256-cbc -d -a -iter 2 -pass env:SSLPASS 2>/dev/null; unset SSLPASS; }
sslTextPwd () { [[ -z $SSLPASS ]] && read -s -p "Password: " SSLPASS && export SSLPASS; }
@olomor
olomor / tarpigz.sh
Last active April 9, 2020 22:27
How about compressing using targz in a tenth of the time, using more than one core cpu? Use pigz!!! :)
function tarpigz() {
BLOCKSIZE=$( grep "^cache size" /proc/cpuinfo |uniq |cut -d" " -f3 )
NUMCPU=$(( `nproc` / 2 ))
PIGZ="pigz --best --blocksize ${BLOCKSIZE} --independent --processes ${NUMCPU} --synchronous"
time tar -cvf - ${2} |$PIGZ >${1}
}