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 | |
#Small function to give text status of OK/FAIL to commands | |
tstatus() { | |
RETCODE=$(echo $?) | |
[[ $RETCODE -eq 0 ]] && printf '\e['$(($(tput cols)-10))'G [ \e[32mOK\e[0m ]\n' | |
[[ $RETCODE -eq 1 ]] && printf '\e['$(($(tput cols)-10))'G [\e[31mFAIL\e[0m]\n' | |
return $RETCODE | |
} |
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
#This will print the length of the longest field in a column across all records | |
# awk -F"|" '{ for (i=1; i<=NF; i++) { max[i] = length($i) > max[i] ? length($i) : max[i] ;ncols = i > ncols ? i : ncols }} END { for (col=1; col <= ncols; col++) {printf "%d\n", max[col]}}' | |
##This example has pipe separated record adjust field separator as needed | |
##This example only prints the max length of each column (in order) with a CR, adjust printf statement as needed | |
### Sample data #### | |
FOO=' | |
Host|SysID|DevID|Name|Model|Part ID|UUID|LABEL|FS|MNT|Bootable | |
node01ob20|pk3fqr|73|sda|KINGSTON SV300S3|48|f87c08cb-c444-4f81-af8a-5ed22947f63d|efi|fat32|/boot/efi|true | |
node01ob20|pk3fqr|73|sda|KINGSTON SV300S3|49|3a8024f2-0aa0-4005-8400-cf8d4a3d175d|root|ext4|/|false |
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
juju-fix-missing-gpg-keys() { | |
#search juju debug log for missing GPG keys and apply them to all servers in the model | |
local -a MISSING_KEYS=($((juju debug-log --no-tail --replay|awk '/GPG error/{print $NF}')|sort -u)) | |
local -a MACHINES=($(juju machines|awk '/^[0-9]+/&&/started/{print $1}')) | |
for k in ${MISSING_KEYS[@]};do printf "%s $k\n" ${MACHINES[@]};done|\ | |
xargs -n2 -P0 bash -c 'juju 2>/dev/null ssh $0 sudo apt-key 2>/dev/null adv --recv-key --keyserver keyserver.ubuntu.com $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
maas-ready-nic-info () { | |
( printf "System|ID|VLAN|Tag|MAC|Name|Child of|Parent to|Hostname|Available Subnets on current VLAN\n"; | |
sudo -u postgres psql -P pager=off -F"|" --no-align -t maasdb -c \ | |
"SELECT node.system_id,interface.id,interface.vlan_id,vlan.vid,interface.mac_address,interface.name,ifparent.parent_id,ifchild.child_id,node.hostname, array_to_string(array_agg(distinct subnet.cidr),',') AS niclist \ | |
FROM maasserver_interface interface \ | |
LEFT OUTER JOIN maasserver_vlan vlan ON vlan.id = interface.vlan_id \ | |
LEFT OUTER JOIN maasserver_subnet subnet ON subnet.vlan_id = interface.vlan_id \ | |
LEFT OUTER JOIN maasserver_node node ON interface.node_id = node.id \ | |
LEFT OUTER JOIN maasserver_interfacerelationship ifparent ON interface.id = ifparent.child_id \ | |
LEFT OUTER JOIN maasserver_interfacerelationship ifchild ON interface.id = ifchild.parent_id \ |
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
maas-insert-boot-param() { | |
local DESC="\e[1m${FUNCNAME}\e[0m: Insert a boot paramter into a specific, or all existing tags.\n" | |
maas-insert-boot-param_usage() { | |
printf "\n${DESC}\n" | |
printf "\e[1mUsage\e[0m: ${FUNCNAME%%_*} -p <param> [-t <tag>]\n\n" | |
printf "\e[1mOptions\e[0m:\n" | |
printf "\e[2G -p, --param \e[20GRequired: boot parameter to add\n" | |
printf "\e[20GEx: apparmor=0\n" | |
printf "\e[20GTip: Enclose multiple params in single quotes\n\n" | |
printf "\e[2G -t, --tag \e[20GOptional: Add only to a specific tag\n" |
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
####OpenStack Test Functions###### | |
#This file should be sourced, not ran | |
###Prettyfication section#### | |
tstatus() { | |
RC=$(echo $?) | |
[[ $RC -eq 0 ]] && { printf '\e[75G\e[1;37m[ \e[1;32mOK\e[1;37m ]\e[0m\n';return $RC; } | |
[[ $RC -eq 1 ]] && { printf '\e[75G\e[1;37m[\e[1;31mFAIL\e[1;37m]\e[0m\n';return $RC; } | |
} |
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
curl -sSL https://timezoneapi.io/api/ip|\ | |
jq -r 'keys[0] as $k|.[$k]|to_entries[]|select((.key != "timezone" and .key != "datetime"))|"\(.key): \(.value)"' |
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
# This command will refresh all installed snaps in parallel. | |
# If snap was installed with classic confinment, but snap list | |
# does not report that fact, just put that snap in the first awk | |
# if statement (pipe separated) | |
snap list|awk '/^[a-z]/{if (/classic|charm/) print $1 " --classic";if (!/classic/) print $1}'|xargs -L1 -P0 sudo snap refresh |
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
#Updated to print full names when they include spaces and to display in columns | |
showrgb| \ | |
awk '{printf "%s", "\"\\e[1;38;2;"$1";"$2";"$3"m"; for(i=4;i<=NF;i++){printf "%s ", $i};printf "\\e[0m\"\n"}'| \ | |
xargs -L1 echo -e| \ | |
column |
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
sp() { printf "%0.0s " $(seq 1 $1); } | |
Example: | |
# Say you need to add two lines near the end of /etc/security/limits.conf | |
Orig file: | |
#<domain> <type> <item> <value> | |
# | |
#* soft core 0 | |
#root hard core 100000 |