Skip to content

Instantly share code, notes, and snippets.

@asaaki
Last active December 16, 2017 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asaaki/6143757 to your computer and use it in GitHub Desktop.
Save asaaki/6143757 to your computer and use it in GitHub Desktop.
Shell Snippets
#!/usr/bin/sh
# Count lines of multiple files (recursively):
find source_dir -name "*.ext" -exec wc -l {} +
# 7 digit sha1 transformed timestamp name:
### simple: date +%s%N | \
### more unique
/usr/lib/systemd/systemd-timestamp | \
sha1sum | \
cut -f 1 -d ' ' | \
cut -b 1-7
# random string
cat /dev/urandom | \
tr -dc 'a-f0-9' | \
fold -w 7 | \
head -n 1
# another random string
dd if=/dev/random count=1 | \
openssl base64 | \
cut -b 1-7
# some random UINTs (8bit)
dd if=/dev/urandom bs=100 count=1 2>/dev/null | \
hexdump -v -e '1/1 "%u "'
# get MAC address (from device which is multicast-capable!)
ip link | \
grep -A 2 MULTICAST | \
grep ether | \
awk '{print $2}' | \
sed 's/:/-/g'
# set hostname on arch:
/usr/bin/hostnamectl set-chassis server
/usr/bin/hostnamectl set-hostname $NEWHOSTNAME
# save this as `/opt/update-hostname.sh` to be used by `update-hostname.service`
# read temperature of thermal sensors (if available):
cat /sys/class/thermal/thermal_zone*/temp
# your python should be default to python2?
# assumed you have ~/bin in your PATH:
ln -s /usr/bin/python2 $HOME/bin/python
# cpu info
cat /proc/cpuinfo
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
# list merged branches with date/age
for k in $(git branch -a --merged|grep -v "\->"|sed s/^..//); do
echo -e $(git log -1 --pretty=format:"%ci (%cr)" "$k") "$k"
done | sort
[Unit]
Description=Update Hostname
Wants=network.target
Before=network.target
[Service]
Type=oneshot
ExecStart=/opt/update-hostname.sh
ExecReload=/opt/update-hostname.sh
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment