Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
gregjhogan / speedtest-cli.sh
Last active June 7, 2019 21:26
bash speed test
curl https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
# EXAMPLE OUTPUT
# ==============
# opening device 0xddcc
# connected
# tester present ...
# read data by id: boot software id ...
# 39990-TVA-A110
# read data by id: application software id ...
# 39990-TVA-A150
# read data by id: application data id ...
@gregjhogan
gregjhogan / tftp-server.sh
Created March 29, 2019 00:50
tftp server and logging example
# start tftp server
docker run --rm --network=host --name=tftp -it -v /dev/log:/dev/log -v /<path>/<to>/tftp:/tftp pghalliday/tftp -Lvvv /tftp
# view logs while running
tail -f /var/log/syslog
# request file
tftp <hostname> << EOF
get /tftp/test.txt
EOF
@gregjhogan
gregjhogan / add-ssh-known-host.sh
Created March 11, 2019 22:58
add list of ssh hosts to known_hosts
HOSTS=(
host1
host2
host3
)
for HOST in "${HOSTS[@]}"; do ssh-keyscan $HOST >> $HOME/.ssh/known_hosts; done
@gregjhogan
gregjhogan / docker-remove-all-stopped-containers.sh
Created January 24, 2019 20:17
docker remove all stopped containers
docker rm $(docker ps -q --filter "status=exited")
@gregjhogan
gregjhogan / bash-log-to-file-if-not-interactive.sh
Created January 23, 2019 20:15
bash log to file if not running interactively
#!/usr/bin/env bash
set -e
# log to file if not running interactively
if [[ ! -t 1 ]]; then
exec >> >(tee /var/log/$(basename ${0%.*}).log) 2>&1
fi
echo "hello world!"
@gregjhogan
gregjhogan / dstat.sh
Last active February 14, 2019 05:07
dstat with most useful flags
dstat -v --disk-util -rn
@gregjhogan
gregjhogan / generate-random-password.sh
Created January 20, 2019 03:11
Generate Random Password
openssl rand -base64 30
date +%s | sha256sum | base64 | head -c 32 ; echo
@gregjhogan
gregjhogan / find-and-delete-empty-dirs.sh
Created January 15, 2019 05:41
find and delete empty directories
find /<path>/<to>/<base> -type d -empty -print | xargs -I '{}' rmdir '{}'
@gregjhogan
gregjhogan / mysql-dump-query-to-file.sh
Created January 9, 2019 22:44
mysql dump query to file
mysql -h <hostname> -u <username> -p -sN -e "select json_object('key1', 1, 'key2', 2);" <database> > <filename>