This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 7am-9am,5pm-9pm | |
ek_peak_current="0.2213" | |
# 9am-5pm, 9pm-11pm | |
ek_off_peak_shoulder_current="0.1372" | |
# 11pm to 7am | |
ek_off_peak_night_current="0.1107" | |
ek_daily_current="1.99" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__complete_ssh_host() { | |
local ssh_known_file ssh_known_list partial_word | |
ssh_known_file="${HOME}/.ssh/known_hosts" | |
[[ -r "${ssh_known_file}" ]] || return 1 | |
ssh_known_list=$(awk '{print $1}' "${HOME}"/.ssh/known_hosts | tr ',' '\n' | sort | uniq) | |
partial_word="${COMP_WORDS[COMP_CWORD]}"; | |
mapfile -t COMPREPLY < <(compgen -W "${ssh_known_list}" -- "${partial_word}") | |
return 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while read -r file; do | |
printf -- '%s;%s\n' "$(md5sum < "${file}" | awk '{print $1}')" "$(stat -c "%a;%U;%G;%n" "${file}")" | |
done < <(find . -type f -print) > data.manifest | |
51e7d30fab63ba29f86bcf6f807b88cf;674;jenkins;jenkins;./org.jenkinsci.plugins.gitclient.JGitApacheTool.xml | |
0a363d9165e56856e0f693152fc0fe88;644;jenkins;jenkins;./queue.xml.bak | |
d99c0a9f0563b0203c6ce7d778a14338;674;jenkins;jenkins;./hudson.plugins.disk_usage.DiskUsageProperty.xml | |
671c3c9ef67c47d75f73d4d9280e2b28;674;jenkins;jenkins;./org.jenkinsci.plugins.workflow.libs.GlobalLibraries.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
table_max_width="${2:-80}" | |
# TO-DO: Add some smarts at this point to minimise issues caused by uneven column widths | |
# Subtract for our pipechars | |
# ---------|-----|------|-----|------|-----|------| | |
# ^ ^ ^ ^ These particular guys | |
columns_max_width="$(( table_max_width - 4 ))" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt() { | |
case "${1}" in | |
(history) | |
mapfile -t apt_hist < <(zgrep -A 1 "^Start-Date" /var/log/apt/history.log* | grep -v -- "^--$") | |
left_col_width="$(( "${COLUMNS:-$(tput cols)}" - 30 ))" | |
# The format of this printf invocation needs to be tweaked | |
printf -- "| %-${left_col_width}s | %s\\n" "Command line" "Date and time" | |
printf -- '%*s\n' "${COLUMNS:-$(tput cols)}" | tr ' ' "-" | |
for (( i=0; i<"${#apt_hist[@]}"; i++ )); do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# Generates deny list for nginx | |
# This blocks known bad IP's that are scanning for log4shell exploits | |
if ! command -v curl >/dev/null 2>&1; then | |
printf -- '%s\n' "This script requires 'curl'" >&2 | |
exit 1 | |
fi | |
# Remote source to pull down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
readlink_f() { | |
( | |
_count=0 | |
_target="${1:?No target specified}" | |
# Ensure that a customised CDPATH doesn't interfere | |
CDPATH='' | |
# Ensure that target actually exists and is actually a symlink | |
[ -e "${_target}" ] || return 1 | |
[ -L "${_target}" ] || return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tzlookup() { | |
local err cmd lat long | |
err=0 | |
for cmd in curl jq; do | |
command -v "${cmd}" >/dev/null 2>&1 || (( ++err )) | |
done | |
(( err > 0 )) && { printf -- '%s\n' "Requires 'curl' and 'jq'" >&2; return 1; } | |
lat="${1:?No latitude value supplied}" | |
long="${2:?No longitude value supplied}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A portable alternative to exists/get_command/which/type | |
pathfind() { | |
OLDIFS="${IFS}" | |
IFS=: | |
for prog in ${PATH}; do | |
if [[ -x "${prog}/$*" ]]; then | |
printf -- '%s\n' "${prog}/$*" | |
IFS="${OLDIFS}" | |
return 0 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Regenerate your known_hosts file after rotating your keys | |
# Generate a list of hosts that we're more likely to care about, divined from our shell history | |
# Adjust filtering in the final 'grep -Ev' to suit your needs | |
# n.b. typos and stale entries will fail in subsequent steps, so don't sweat this too much | |
get_historical_hosts() { | |
grep "^ssh " "${HOME}/.bash_history" | | |
tr " " "\n" | | |
grep -Ev '^ssh$|^-v+|^-[a-zA-Z]$|^.*.pem$|^".*.pem"$|^raw$|^$|^~|^.$' | |
NewerOlder