My .bashrc: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
(42 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 1: | Linha 1: | ||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash line=1> | ||
echo Profile Loaded | echo Profile Loaded | ||
# _ | |||
# / \ _____ _ _ __ ___ | |||
# / _ \ |_ / | | | '__/ _ \ | |||
# / ___ \ / /| |_| | | | __/ | |||
#/_/ \_\/___|\__,_|_| \___| | |||
# | |||
function | function AZ_KV_SET_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done;if [ $# -eq 0 ] ; then echo HELP; echo $0 "SUB_ID VAULT_NAME SECRET_NAME VALUE \"TAG1=VALUE;TAG2=VALUE\"" ; else az keyvault secret set --subscription $1 --vault-name $2 --name $3 --value "$4" --tags $(echo $5 | tr ';' ' ') ;fi ; } | ||
function | function AZ_KV_FIND_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; cat $1 | jq -r '.[]|.name' | grep -i $2 | while read KEY; do cat $1 | jq -r '.[]|select(.name=="'$KEY'")' ;done ; } | ||
function | function AZ_KV_LIST_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ;if [ $# -eq 0 ] ; then echo HELP; echo $0 "SUB_ID VAULT_NAME " ; else az keyvault secret list --subscription $1 --vault-name $2 | jq -r '.[]|[{"name": .name, "updated": .attributes.updated, "tags": .tags}]';fi ; } | ||
function | function AZ_KV_SHOW_ALL_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ;if [ $# -eq 0 ] ; then echo HELP; echo $0 "SUB_ID VAULT_NAME " ; else az keyvault secret list --subscription $1 --vault-name $2 | jq -r ".[]|.id" | while read ID; do az keyvault secret show --id $ID | jq -r '[{"name": .name, "secret": .value, "tags": .tags}] ';done ;fi ; } | ||
function | function AZ_KV_GET_SECRET_FROM_LIST() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; cat $1 | export RETORNO=$(jq -r '.[]|select(.name=="'$2'")'); echo $RETORNO |jq ; echo $RETORNO | jq -r '.tags'| grep : | sed -e "s/ *//g" -e "s/\"//g" -e "s/:/=/g" -e "s/,/\;/g" | tr '\n' ' '| sed -e "s/ //g" -e "s/$/\n/g"; } | ||
function | function AZ_KV_GET_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done;az keyvault secret list --subscription $1 --vault-name $2 -o json | jq -r '.[]|select(.name=="'$3'")' ; } | ||
function | function AZ_KV_SHOW_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done;az keyvault secret show --subscription $1 --vault-name $2 -n $3 -o json ; } | ||
function | function AZURE_GET_VM_IPS() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; if [ $# -ne 2 ] ; then echo -e "NOT ENOUGH ARGUMENTS\n$0 SUB_ID RG_NAME" ; return 1 ; fi; az vm list --subscription $1 -g $2 -d | jq -r ".[]|[ .name,.networkProfile.networkInterfaces[].id]| @csv" | while IFS=\" read VM{1..5}; do echo $VM2 $VM4;done | while read VMNAME NIC; do echo $VMNAME $(az network nic show --ids $NIC| jq -r ".ipConfigurations[].privateIpAddress") ;done ; } | ||
function VMSS_RUN_ALL_INSTANCE() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; if [ $# -ne 4 ] ; then echo -e "NOT ENOUGH ARGUMENTS\n$0 SUB_ID RG_NAME VMSS_NAME \"COMMANDS\"" ; return 1 ; fi; az vmss list-instances --subscription $1 -g $2 -n $3 | jq -r ".[].instanceId" | while read ID; do az vmss run-command invoke --subscription $1 -g $2 -n $3 --command-id RunShellScript --instance-id $ID --scripts "$4" | jq -r ".value[].message" ; done ; } | |||
function AZ_VMSS_SSH_ALL_INSTANCE() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; if [ $# -ne 4 ] ; then echo -e "\nNOT ENOUGH ARGUMENTS\n$0 SUB_ID RG_NAME VMSS_NAME SSH_USER\n" ; return 1 ; fi; az vmss list-instances --subscription $1 -g $2 -n $3 | jq -r '.[]|.networkProfile.networkInterfaces[].id' | while read NIC; do az vmss nic show --ids $NIC| jq -r ".ipConfigurations[].privateIpAddress"| while read ADDRESS; do screen -t $2_$3_$ADDRESS sshpass -f ~/.ssh/account ssh -XC -A -o ConnectTimeout=3 -l $4 $ADDRESS & done; done ; } | |||
function FIGLET() { for BIN in {figlet}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; figlet $1 | sed -e "s/^/\#/g" ; } | |||
function AZ_GET_SUB() { | |||
az account list -o json | jq -r '.[]|.id' |\ | |||
while read SUBID | |||
do | |||
echo $SUBID >&2 | |||
echo $SUBID | |||
done | |||
} | |||
function AZ_GET_AKS_BY_SUB() { | |||
while read SUBID | |||
do | |||
az aks list --subscription $SUBID | jq -r '.[]|.id' | \ | |||
while IFS=/ read ID{1..9} | |||
do | |||
echo $ID3 $ID5 $ID9 >&2 | |||
echo $ID3 $ID5 $ID9 | |||
done | |||
done | |||
} | |||
function AZ_GET_OIDC_URL() { | |||
while read SUB RG NAME | |||
do | |||
az aks show \ | |||
--subscription $SUB \ | |||
--resource-group $RG \ | |||
--name $NAME |\ | |||
jq -r 'paths(scalars) as $path | { ($path | map(tostring) | join("_")): getpath($path) }| to_entries|map("\(.key)=\(.value|tostring)")|.[]' | grep oidcIssuerProfile_issuerUrl |\ | |||
while IFS== read KEY VALUE | |||
do | |||
echo $SUB $RG $NAME $VALUE | |||
done | |||
done | |||
} | |||
function AZ_GET_AKS_CREDENTIAL() { | |||
while read SUB RG NAME | |||
do | |||
az aks get-credentials \ | |||
--subscription $SUB \ | |||
--resource-group $RG \ | |||
--name $NAME \ | |||
-f aad-${NAME} | |||
az aks get-credentials \ | |||
--subscription $SUB \ | |||
--resource-group $RG \ | |||
--name $NAME \ | |||
-a \ | |||
-f aad-${NAME}-admin | |||
done | |||
} | |||
#GET_SUB | GET_AKS_BY_SUB | GET_AKS_CREDENTIAL | |||
#GET_SUB | GET_AKS_BY_SUB | GET_OIDC_URL | |||
alias az_subscription='az account list --query "[].[name,id]" -o tsv | column -t' | |||
alias az_on="source $HOME/Projetos/azc/bin/activate" | |||
alias azlogin="az login --use-device-code" | |||
alias az_location='az account list-locations --query "[].[name]" -o tsv' | |||
# _ __ _ _ | |||
#| |/ / _| |__ ___ _ __ _ __ ___| |_ ___ ___ | |||
#| ' / | | | '_ \ / _ \ '__| '_ \ / _ \ __/ _ \/ __| | |||
#| . \ |_| | |_) | __/ | | | | | __/ || __/\__ \ | |||
#|_|\_\__,_|_.__/ \___|_| |_| |_|\___|\__\___||___/ | |||
# | |||
function K_GET_CRASHED_PODS() { | |||
if [ $# -ne 1 ] | |||
then | |||
return | |||
else | |||
export RESTARTS=$1 | |||
kubectl get pods -A -o json | \ | |||
jq -r ''' | |||
.items[]| | |||
[ | |||
{ | |||
"namespace": .metadata.namespace, | |||
"name": .metadata.name, | |||
"containerStatuses": (.status|.containerStatuses|. |= if .==null then "NOK" else . end) | |||
} | |||
]| | |||
.[]| | |||
select(.containerStatuses!="NOK")| | |||
[ | |||
{ | |||
"namespace": .namespace, | |||
"name": .name, | |||
"restart": (.containerStatuses[].restartCount|tonumber), | |||
"message": .containerStatuses[].state.waiting.message, | |||
"reason": .containerStatuses[].state.waiting.reason | |||
} | |||
]| | |||
.[]| | |||
select(.restart>'''${RESTARTS}''')| | |||
select((.reason=="CrashLoopBackOff") or (.reason=="RunContainerError")) | |||
''' | |||
fi | |||
} | |||
function K_EXCLUDE_RUNNING() { while read -r LINE; do echo $LINE;done |egrep -v "1/1|2/2|3/3|4/4|Completed";} | |||
function K_INCLUDE_RUNNING() { while read -r LINE; do echo $LINE;done |egrep "1/1|2/2|3/3|4/4|Completed" ;} | |||
function K_GET_HELM_MANIFEST() { function DO_STUFF() { kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| cat -n ; read LINE ; export SECRET=$(kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| head -n $LINE | tail -n 1) ; kubectl -n $1 get secret $SECRET -o json | jq -r '.data.release' | base64 -d| base64 -d | gzip -d | jq -r '.manifest' ; } ; export RC=3 ; for BIN in {kubectl,jq} ; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ] ; then echo $BIN not found ; export RC=1 ; return 1 ; else if [ $(file "$(which $BIN)" 2>&1 >/dev/null ; echo $?) -ne 0 ] ; then echo $BIN not found ; export RC=1 ; return 1 ; fi ; fi ; done ; if [ $RC -eq 3 ] ; then DO_STUFF "$1" ; fi ; } | |||
function K_GET_HELM_MANIFEST() { | |||
function DO_STUFF() { | |||
kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| cat -n | |||
read LINE | |||
export SECRET=$(kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| head -n $LINE | tail -n 1) | |||
kubectl -n $1 get secret $SECRET -o json | \ | |||
jq -r '.data.release' | \ | |||
base64 -d| base64 -d | gzip -d | \ | |||
jq -r '.manifest' | |||
} | |||
export RC=3 | |||
for BIN in {kubectl,jq} | |||
do | |||
if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ] | |||
then | |||
echo $BIN not found | |||
export RC=1 | |||
return 1 | |||
else | |||
if [ $(file "$(which $BIN)" 2>&1 >/dev/null;echo $?) -ne 0 ] | |||
then | |||
echo $BIN not found | |||
export RC=1 | |||
return 1 | |||
fi | |||
fi | |||
done | |||
if [ $RC -eq 3 ] | |||
then | |||
DO_STUFF "$1" | |||
fi | |||
} | |||
function K_GET_CONTAINER_RUNNING_BY_NAMESPACE() { for BIN in {kubectl,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; while read NS; do kubectl -n $NS get pods -o json;done | jq -r '.items[]|[(.metadata|.namespace,.name),(.status.containerStatuses[]|.name,.state.running)]' ;} | |||
function K_GET_ALL() { for BIN in {yq,kubectl}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; kubectl -n $1 get $(kubectl api-resources --verbs=list --namespaced -o name | while read KIND; do kubectl -n $1 get --ignore-not-found $KIND --no-headers | awk '{print $1}'| while read RESOURCE; do echo ${KIND} ;done ;done | sort -u | tr '\n' ',' | sed -e "s/,$//g") ;} | |||
function K_GET_FROM_ALL_KINDS() { for BIN in {yq,kubectl}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; kubectl api-resources --verbs=list --namespaced -o name | while read KIND; do kubectl -n $1 get --ignore-not-found $KIND --no-headers | awk '{print $1}'| while read RESOURCE; do echo $(date) $1/${KIND}_${RESOURCE}.yml ; kubectl -n $1 get $KIND $RESOURCE -o yaml | yq 'del(.metadata.creationTimestamp,.metadata.uid,.status,.metadata.generation,.metadata.resourceVersion,.metadata.annotations."cni*",.spec.clusterIP*,.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' > ${KIND}_${RESOURCE}.yml;done ;done; } | |||
function K_DELETE_PODS_BY_NAMESPACE() { kubectl -n $1 get pods --no-headers; kubectl -n $1 delete pods $(kubectl -n $1 get pods --no-headers | awk '{print $1}' ); sleep 30 ; kubectl -n $1 get pods --no-headers -o wide ;} | |||
function kcfg() { | function kcfg() { | ||
Linha 40: | Linha 199: | ||
fi | fi | ||
} | } | ||
function k_logs() { k -n $1 logs $(k -n $1 get pods --no-headers | c1 | head -n 1) ; } | |||
function K_PATCH_NS() { | |||
kubectl \ | |||
patch ns "$1" \ | |||
--type='json' \ | |||
-p=$2 | |||
} | |||
function K_PATCH_DEPLOYMENT() { | |||
kubectl \ | |||
-n "$1" patch deployment "$2" \ | |||
--type='json' \ | |||
-p=$3 | |||
} | |||
function K_GET_DEPLOYMENT_BY_NS() { | |||
kubectl -n "$1" get deployment -o json | jq -r '.items[]|.metadata.name' | |||
} | |||
function K_GET_DEPLOYMENT_LABELS() { | |||
kubectl -n "$1" get deployment -o json | \ | |||
jq -r '.items[]|.metadata.labels|to_entries|map("\(.key)=\(.value|tostring)")|.[]' | |||
} | |||
function K_GET_NS_LABELS() { | |||
kubectl get ns "$1" -o json | \ | |||
jq -r '.metadata.labels|to_entries|map("\(.key)=\(.value|tostring)")|.[]' | |||
} | |||
function K_GET_NS_WITH_TIMEBOMB() { | |||
if [ $# -eq 1 ] | |||
then | |||
if [ "$1" == "true" ] | |||
then | |||
export TIMEBOMB=NOK | |||
else | |||
export TIMEBOMB=OK | |||
fi | |||
kubectl get ns -o json | \ | |||
jq -r ''' | |||
.items[]| | |||
.metadata.labels| | |||
{ | |||
"name": .name, | |||
"kubeomatic-io-timebomb": (."kubeomatic-io-timebomb" | . |= if .==null then "NOK" else . end), | |||
"kubeomatic-io-timebomb-cluster": (."kubeomatic-io-timebomb-cluster" | . |= if .==null then "NOK" else . end) | |||
} | | |||
select(."kubeomatic-io-timebomb" != "'$TIMEBOMB'")| | |||
[.name,."kubeomatic-io-timebomb-cluster"] | @tsv | |||
''' | column -t | |||
else | |||
echo K_GET_NS_WITH_TIMEBOMB Not enough arguments >&2 | |||
fi | |||
} | |||
function K_GET_NS_BY_LABEL() { | |||
if [ $# -eq 3 ] | |||
then | |||
kubectl get ns -A -o json | \ | |||
jq -r ''' | |||
.items[]| | |||
.metadata| | |||
{ | |||
"name": .name, | |||
"'$1'": (.labels."'$1'" | . |= if .==null then "NOK" else . end) | |||
} | | |||
select(."'$1'" '$2' "'$3'")| | |||
[.name,."'$1'"] | @tsv | |||
''' | column -t | |||
else | |||
echo K_GET_NS_BY_LABEL Not enough arguments >&2 | |||
fi | |||
} | |||
function K_GET_DEPLOYMENT_BY_LABEL() { | |||
if [ $# -eq 3 ] | |||
then | |||
kubectl get deployments -A -o json | \ | |||
jq -r ''' | |||
.items[]| | |||
.metadata.labels| | |||
{ | |||
"name": .name, | |||
"'$1'": (."'$1'" | . |= if .==null then "NOK" else . end) | |||
} | | |||
select(."'$1'" '$2' "'$3'")| | |||
.metadata|[.namespace,.name] | @tsv | |||
''' | column -t | |||
else | |||
echo K_GET_DEPLOYMENT_BY_LABEL Not enough arguments >&2 | |||
fi | |||
} | |||
alias k=kubectl | |||
alias ki="k -n ingress" | |||
alias km="k -n monitoring" | |||
alias ks="k -n kube-system" | |||
# __ __ _ | |||
#| \/ (_)___ ___ | |||
#| |\/| | / __|/ __| | |||
#| | | | \__ \ (__ | |||
#|_| |_|_|___/\___| | |||
# | |||
function JQ_FLAT() { while read -r LINE; do echo $LINE;done | jq -r 'paths(scalars) as $path | { ($path | map(tostring) | join("_")): getpath($path) }| to_entries|map("\(.key)=\(.value|tostring)")|.[]' ; } | |||
function COMPRESS_ENCRYPT() { | |||
for BIN in {pv,pigz,openssl,lscpu,split,tar}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done | |||
if [ $# -ne 3 ] || [ ! -e $2 ] || [ -e $3 ] || [ $(echo $1 | grep ^[0-9]$ | wc -l ) -eq 0 ] | |||
then | |||
echo FAIL | |||
echo COMPRESS_ENCRYPT LEVEL SOURCE DESTINATION | |||
return 1 | |||
fi | |||
export LEVEL=$1 | |||
export SRC="$2" | |||
export DST="$3" | |||
export ITER=$(expr $(expr $[ $RANDOM % 100 + 10000 ] \* $[ $RANDOM % 10000 + 100 ] + $[ $RANDOM % 10 ])) | |||
export CPUN=$( lscpu| grep "^CPU(s):" | awk '{print $2}') | |||
export SIZE=$(du -sk $SRC| awk '{print $1}')k | |||
mkdir $DST | |||
echo COMPRESS AND ENCRYPT | |||
echo ITER=$ITER | |||
tar cf - $SRC | pv -s $SIZE | pigz -p $CPUN -$LEVEL | openssl aes-256-cbc -iter $ITER -pbkdf2 -salt -e -in - -out - | split -b 256m - "$DST"/bkp | |||
} | |||
function CENSOR() { | |||
coproc stdbuf -o0 sed "s/$1/***/g" & | |||
while read -r LINE | |||
do | |||
echo "$LINE" >&${COPROC[1]} | |||
read -u ${COPROC[0]} msg | |||
echo "$msg" | |||
done | |||
kill $COPROC_PID | |||
} | |||
function CENSOR_BUILD() { | |||
export SECRETSTRING='' | |||
echo $1 | tr ';' '\n' | \ | |||
while read SECRET | |||
do | |||
export SECRETSTRING="CENSOR $SECRET | $SECRETSTRING" | |||
echo $SECRETSTRING | |||
done | tail -n 1 | sed -e "s/|$//g" | |||
} | |||
function DU_ALL() { | |||
ls -1a | while IFS=\; read obj ; do du -sk $obj 2>/dev/null;done | sort -n -k1 | awk '{ if ($1 < 1024) print "\033[1;32m"$1"K " $2 "\033[0m" ; else if ( $1 >= 1024 && $1 <= 1048576 ) print "\033[1;34m"$1/1024"M " $2"\033[0m"; else if ($1 > 1048576 ) print "\033[1;31m"$1/1048576"G " $2"\033[0m"}' | |||
} | |||
function SNAPCLEAN() { sudo snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do sudo snap remove "$snapname" --revision="$revision" ;done ; } | |||
function FSTAB_MP() { if [ $# -ne 4 ] ; then echo -e "Example:\nFUNCTION_NAME LV_NAME FS_TYPOE /PATH/TO/FS" ; else echo UUID=$(blkid | grep $1 | awk -F \" '{print $2}') $2 $3 defaults 1 2 ; fi ; } | |||
function ip_range() { seq $2 $3 | while read C; do seq $4 $5 | while read D ; do echo $1.$C.$D ; done;done ; } | function ip_range() { seq $2 $3 | while read C; do seq $4 $5 | while read D ; do echo $1.$C.$D ; done;done ; } | ||
Linha 47: | Linha 354: | ||
function testrange() { seq $2 $3 | while read valor; do testport $1 $valor & done ; } | function testrange() { seq $2 $3 | while read valor; do testport $1 $valor & done ; } | ||
function | function ealias() { alias $1 | awk -F \' '{print $2}' ; } | ||
function SSHLOOP() { if [ $# -ne 1 ] ; then echo -n "NOT ENOUGH ARGUMENTS\n$0 SERVERNAME" ; return 1 ; fi; while true; do sshpass -f ~/.ssh/senha ssh -XC -A -o ConnectTimeout=3 $1 ; sleep 1;date;done ; } | |||
function loop() { if [ $# -ne 2 ] ; then echo -n "NOT ENOUGH ARGUMENTS\n$0 \"commands\" seconds" ; return 1 ; fi; while true; do date; bash -c "$1"; sleep $2 ;done ; } | |||
function | function get_terraform_ips() { find . -type f -name terraform.tfstate -exec grep -w private_ip_address {} \; | awk -F \" '{ print $4} ' | sort -u ; } | ||
function BACKUPNOW() { | function BACKUPNOW () { | ||
export $ | for BIN in {pv,split,pigz}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; | ||
if [ -z $1 ] | |||
then | |||
export THREAD=8 | |||
else | |||
export THREAD=$1 | |||
fi | |||
if [ -z $2 ] | |||
then | |||
export LEVEL=9 | |||
else | |||
export LEVEL=$2 | |||
fi | |||
export DATADIR=$(date +"%y%m%d") | export DATADIR=$(date +"%y%m%d") | ||
export DATAPATH=$ | export DATAPATH=PATH TO SOMEWHERE | ||
export LIST=$(ls -1a | egrep -v "^OneDrive|^.$|^..$|^Library|^.gradle|^.Trash|^.nuget|^.lima|^Downloads") | |||
export ALLSIZE=$(echo $LIST | while IFS=\; read obj; do du -sk $obj 2>/dev/null;done|awk '{ s = s + $1} END { print s"k"}') | |||
mkdir -p $DATAPATH | mkdir -p $DATAPATH | ||
tar cf - $( | echo SIZE= $ALLSIZE, THREAD= $THREAD, LEVEL=$LEVEL | ||
export ITERN=$(expr $(expr $[ $RANDOM % 100 + 100000 ] \* $[ $RANDOM % 10000 + 100 ] + $[ $RANDOM % 10 ])) | |||
while | tar cf - $(echo $LIST | tr '\n' ' ')2>/dev/null| pv -s $ALLSIZE | pigz -p $THREAD -$LEVEL| openssl aes-256-cbc -iter $ITERN -pbkdf2 -salt -e -in - -out - | split -b 256m - "$DATAPATH"/bkp. | ||
} | |||
function GENPASS() { | |||
#!/bin/bash | |||
if [ $# -eq 2 ] | |||
then | |||
export tamanho=$2 | |||
else | |||
export tamanho=13 | |||
fi | |||
function HIGH() { | |||
# tr -dc A-Za-z0-9!?@#_ < /dev/urandom | head -c ${tamanho} | xargs | |||
while true | |||
do | do | ||
export PASSWORD=$(tr -dc 'A-Za-z0-9!?@#_' < /dev/urandom | head -c ${tamanho} | xargs) | |||
if [ $(echo $PASSWORD | sed -e "s/./&\n/g" | egrep "\!|@|#|_|\?" | wc -l ) -gt 2 ] && \ | |||
[ $(echo $PASSWORD | sed -e "s/./&\n/g" | grep "[0-9]" | wc -l ) -gt 2 ] && \ | |||
[ $(echo $PASSWORD | sed -e "s/./&\n/g" | grep "[a-z]" | wc -l ) -gt 2 ] && \ | |||
[ $(echo $PASSWORD | sed -e "s/./&\n/g" | grep "[A-Z]" | wc -l ) -gt 2 ] | |||
then | |||
echo GOOD $PASSWORD | |||
break | |||
else | |||
echo WEAK $PASSWORD | |||
fi | |||
done | |||
} | |||
function MEDIUM() { | |||
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${tamanho} | xargs | |||
} | |||
function LOW() { | |||
tr -dc A-Za-z0-9 < /dev/urandom | head -c ${tamanho} | xargs | |||
} | |||
function NUMBER() { | |||
tr -dc 0-9 < /dev/urandom | head -c ${tamanho} | xargs | |||
} | |||
function HEXA() { | |||
tr -dc A-F0-9 < /dev/urandom | head -c ${tamanho} | xargs | |||
} | |||
function FAKEWWN() { | |||
tr -dc A-F0-9 < /dev/urandom | head -c 16 | xargs | sed -e "s/^0x//g" | sed -r "s/../&:/g" | sed -e "s/$://g" | tr "a-z" "A-Z" | sed -e "s/:$//g" | |||
} | |||
function HELP() { | |||
echo HELP | |||
echo $(echo $0 | tr '\/' '\n' | tail -n 1) \<numero de caracteres\> \| \[ alto \| medio \| baixo \| numero \| hexa \] \<numero de caracteres\> | |||
echo $(echo $0 | tr '\/' '\n' | tail -n 1) \[ alto \| medio \| baixo \| numero \| hexa \| fakewwn\] | |||
echo $(echo $0 | tr '\/' '\n' | tail -n 1) \#Opção default utiliza a complexidade alta com $tamanho caracteres | |||
} | |||
case $1 in | |||
alto) | |||
HIGH | |||
;; | |||
medio) | |||
MEDIUM | |||
;; | |||
baixo) | |||
LOW | |||
;; | |||
numero) | |||
NUMBER | |||
;; | |||
hexa) | |||
HEXA | |||
;; | |||
fakewwn) | |||
FAKEWWN | |||
;; | |||
help) | |||
HELP | |||
;; | |||
ajuda) | |||
HELP | |||
;; | |||
*) | |||
re='^[0-9]+$' | |||
if ! [[ $1 =~ $re ]] | |||
then | |||
export tamanho=13 | |||
else | |||
export tamanho=$1 | |||
fi | |||
HIGH | |||
;; | |||
esac | |||
} | } | ||
function | function TAMANHO() { | ||
ls -1a | while IFS=\; read obj ; do du -sk $obj 2>/dev/null;done | sort -n -k1 | awk '{ if ($1 < 1024) print "\033[1;32m"$1"K " $2 "\033[0m" ; else if ( $1 >= 1024 && $1 <= 1048576 ) print "\033[1;34m"$1/1024"M " $2"\033[0m"; else if ($1 > 1048576 ) print "\033[1;31m"$1/1048576"G " $2"\033[0m"}' | |||
} | } | ||
Linha 92: | Linha 488: | ||
alias c9="awk '{print \$9}'" | alias c9="awk '{print \$9}'" | ||
alias c10="awk '{print \$10}'" | alias c10="awk '{print \$10}'" | ||
alias load_agent="eval $(ssh-agent)" | alias load_agent="eval $(ssh-agent)" | ||
alias load_key=ssh-add | alias load_key=ssh-add | ||
alias loadall='eval $(ssh-agent);ssh-add' | alias loadall='eval $(ssh-agent);ssh-add' | ||
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES | export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES |
Edição atual tal como às 14h45min de 11 de setembro de 2024
echo Profile Loaded
# _
# / \ _____ _ _ __ ___
# / _ \ |_ / | | | '__/ _ \
# / ___ \ / /| |_| | | | __/
#/_/ \_\/___|\__,_|_| \___|
#
function AZ_KV_SET_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done;if [ $# -eq 0 ] ; then echo HELP; echo $0 "SUB_ID VAULT_NAME SECRET_NAME VALUE \"TAG1=VALUE;TAG2=VALUE\"" ; else az keyvault secret set --subscription $1 --vault-name $2 --name $3 --value "$4" --tags $(echo $5 | tr ';' ' ') ;fi ; }
function AZ_KV_FIND_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; cat $1 | jq -r '.[]|.name' | grep -i $2 | while read KEY; do cat $1 | jq -r '.[]|select(.name=="'$KEY'")' ;done ; }
function AZ_KV_LIST_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ;if [ $# -eq 0 ] ; then echo HELP; echo $0 "SUB_ID VAULT_NAME " ; else az keyvault secret list --subscription $1 --vault-name $2 | jq -r '.[]|[{"name": .name, "updated": .attributes.updated, "tags": .tags}]';fi ; }
function AZ_KV_SHOW_ALL_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ;if [ $# -eq 0 ] ; then echo HELP; echo $0 "SUB_ID VAULT_NAME " ; else az keyvault secret list --subscription $1 --vault-name $2 | jq -r ".[]|.id" | while read ID; do az keyvault secret show --id $ID | jq -r '[{"name": .name, "secret": .value, "tags": .tags}] ';done ;fi ; }
function AZ_KV_GET_SECRET_FROM_LIST() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; cat $1 | export RETORNO=$(jq -r '.[]|select(.name=="'$2'")'); echo $RETORNO |jq ; echo $RETORNO | jq -r '.tags'| grep : | sed -e "s/ *//g" -e "s/\"//g" -e "s/:/=/g" -e "s/,/\;/g" | tr '\n' ' '| sed -e "s/ //g" -e "s/$/\n/g"; }
function AZ_KV_GET_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done;az keyvault secret list --subscription $1 --vault-name $2 -o json | jq -r '.[]|select(.name=="'$3'")' ; }
function AZ_KV_SHOW_SECRET() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done;az keyvault secret show --subscription $1 --vault-name $2 -n $3 -o json ; }
function AZURE_GET_VM_IPS() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; if [ $# -ne 2 ] ; then echo -e "NOT ENOUGH ARGUMENTS\n$0 SUB_ID RG_NAME" ; return 1 ; fi; az vm list --subscription $1 -g $2 -d | jq -r ".[]|[ .name,.networkProfile.networkInterfaces[].id]| @csv" | while IFS=\" read VM{1..5}; do echo $VM2 $VM4;done | while read VMNAME NIC; do echo $VMNAME $(az network nic show --ids $NIC| jq -r ".ipConfigurations[].privateIpAddress") ;done ; }
function VMSS_RUN_ALL_INSTANCE() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; if [ $# -ne 4 ] ; then echo -e "NOT ENOUGH ARGUMENTS\n$0 SUB_ID RG_NAME VMSS_NAME \"COMMANDS\"" ; return 1 ; fi; az vmss list-instances --subscription $1 -g $2 -n $3 | jq -r ".[].instanceId" | while read ID; do az vmss run-command invoke --subscription $1 -g $2 -n $3 --command-id RunShellScript --instance-id $ID --scripts "$4" | jq -r ".value[].message" ; done ; }
function AZ_VMSS_SSH_ALL_INSTANCE() { for BIN in {az,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; if [ $# -ne 4 ] ; then echo -e "\nNOT ENOUGH ARGUMENTS\n$0 SUB_ID RG_NAME VMSS_NAME SSH_USER\n" ; return 1 ; fi; az vmss list-instances --subscription $1 -g $2 -n $3 | jq -r '.[]|.networkProfile.networkInterfaces[].id' | while read NIC; do az vmss nic show --ids $NIC| jq -r ".ipConfigurations[].privateIpAddress"| while read ADDRESS; do screen -t $2_$3_$ADDRESS sshpass -f ~/.ssh/account ssh -XC -A -o ConnectTimeout=3 -l $4 $ADDRESS & done; done ; }
function FIGLET() { for BIN in {figlet}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; figlet $1 | sed -e "s/^/\#/g" ; }
function AZ_GET_SUB() {
az account list -o json | jq -r '.[]|.id' |\
while read SUBID
do
echo $SUBID >&2
echo $SUBID
done
}
function AZ_GET_AKS_BY_SUB() {
while read SUBID
do
az aks list --subscription $SUBID | jq -r '.[]|.id' | \
while IFS=/ read ID{1..9}
do
echo $ID3 $ID5 $ID9 >&2
echo $ID3 $ID5 $ID9
done
done
}
function AZ_GET_OIDC_URL() {
while read SUB RG NAME
do
az aks show \
--subscription $SUB \
--resource-group $RG \
--name $NAME |\
jq -r 'paths(scalars) as $path | { ($path | map(tostring) | join("_")): getpath($path) }| to_entries|map("\(.key)=\(.value|tostring)")|.[]' | grep oidcIssuerProfile_issuerUrl |\
while IFS== read KEY VALUE
do
echo $SUB $RG $NAME $VALUE
done
done
}
function AZ_GET_AKS_CREDENTIAL() {
while read SUB RG NAME
do
az aks get-credentials \
--subscription $SUB \
--resource-group $RG \
--name $NAME \
-f aad-${NAME}
az aks get-credentials \
--subscription $SUB \
--resource-group $RG \
--name $NAME \
-a \
-f aad-${NAME}-admin
done
}
#GET_SUB | GET_AKS_BY_SUB | GET_AKS_CREDENTIAL
#GET_SUB | GET_AKS_BY_SUB | GET_OIDC_URL
alias az_subscription='az account list --query "[].[name,id]" -o tsv | column -t'
alias az_on="source $HOME/Projetos/azc/bin/activate"
alias azlogin="az login --use-device-code"
alias az_location='az account list-locations --query "[].[name]" -o tsv'
# _ __ _ _
#| |/ / _| |__ ___ _ __ _ __ ___| |_ ___ ___
#| ' / | | | '_ \ / _ \ '__| '_ \ / _ \ __/ _ \/ __|
#| . \ |_| | |_) | __/ | | | | | __/ || __/\__ \
#|_|\_\__,_|_.__/ \___|_| |_| |_|\___|\__\___||___/
#
function K_GET_CRASHED_PODS() {
if [ $# -ne 1 ]
then
return
else
export RESTARTS=$1
kubectl get pods -A -o json | \
jq -r '''
.items[]|
[
{
"namespace": .metadata.namespace,
"name": .metadata.name,
"containerStatuses": (.status|.containerStatuses|. |= if .==null then "NOK" else . end)
}
]|
.[]|
select(.containerStatuses!="NOK")|
[
{
"namespace": .namespace,
"name": .name,
"restart": (.containerStatuses[].restartCount|tonumber),
"message": .containerStatuses[].state.waiting.message,
"reason": .containerStatuses[].state.waiting.reason
}
]|
.[]|
select(.restart>'''${RESTARTS}''')|
select((.reason=="CrashLoopBackOff") or (.reason=="RunContainerError"))
'''
fi
}
function K_EXCLUDE_RUNNING() { while read -r LINE; do echo $LINE;done |egrep -v "1/1|2/2|3/3|4/4|Completed";}
function K_INCLUDE_RUNNING() { while read -r LINE; do echo $LINE;done |egrep "1/1|2/2|3/3|4/4|Completed" ;}
function K_GET_HELM_MANIFEST() { function DO_STUFF() { kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| cat -n ; read LINE ; export SECRET=$(kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| head -n $LINE | tail -n 1) ; kubectl -n $1 get secret $SECRET -o json | jq -r '.data.release' | base64 -d| base64 -d | gzip -d | jq -r '.manifest' ; } ; export RC=3 ; for BIN in {kubectl,jq} ; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ] ; then echo $BIN not found ; export RC=1 ; return 1 ; else if [ $(file "$(which $BIN)" 2>&1 >/dev/null ; echo $?) -ne 0 ] ; then echo $BIN not found ; export RC=1 ; return 1 ; fi ; fi ; done ; if [ $RC -eq 3 ] ; then DO_STUFF "$1" ; fi ; }
function K_GET_HELM_MANIFEST() {
function DO_STUFF() {
kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| cat -n
read LINE
export SECRET=$(kubectl -n $1 get secret --no-headers| grep helm.sh | awk '{print $1}'| head -n $LINE | tail -n 1)
kubectl -n $1 get secret $SECRET -o json | \
jq -r '.data.release' | \
base64 -d| base64 -d | gzip -d | \
jq -r '.manifest'
}
export RC=3
for BIN in {kubectl,jq}
do
if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]
then
echo $BIN not found
export RC=1
return 1
else
if [ $(file "$(which $BIN)" 2>&1 >/dev/null;echo $?) -ne 0 ]
then
echo $BIN not found
export RC=1
return 1
fi
fi
done
if [ $RC -eq 3 ]
then
DO_STUFF "$1"
fi
}
function K_GET_CONTAINER_RUNNING_BY_NAMESPACE() { for BIN in {kubectl,jq}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; while read NS; do kubectl -n $NS get pods -o json;done | jq -r '.items[]|[(.metadata|.namespace,.name),(.status.containerStatuses[]|.name,.state.running)]' ;}
function K_GET_ALL() { for BIN in {yq,kubectl}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; kubectl -n $1 get $(kubectl api-resources --verbs=list --namespaced -o name | while read KIND; do kubectl -n $1 get --ignore-not-found $KIND --no-headers | awk '{print $1}'| while read RESOURCE; do echo ${KIND} ;done ;done | sort -u | tr '\n' ',' | sed -e "s/,$//g") ;}
function K_GET_FROM_ALL_KINDS() { for BIN in {yq,kubectl}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ; kubectl api-resources --verbs=list --namespaced -o name | while read KIND; do kubectl -n $1 get --ignore-not-found $KIND --no-headers | awk '{print $1}'| while read RESOURCE; do echo $(date) $1/${KIND}_${RESOURCE}.yml ; kubectl -n $1 get $KIND $RESOURCE -o yaml | yq 'del(.metadata.creationTimestamp,.metadata.uid,.status,.metadata.generation,.metadata.resourceVersion,.metadata.annotations."cni*",.spec.clusterIP*,.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' > ${KIND}_${RESOURCE}.yml;done ;done; }
function K_DELETE_PODS_BY_NAMESPACE() { kubectl -n $1 get pods --no-headers; kubectl -n $1 delete pods $(kubectl -n $1 get pods --no-headers | awk '{print $1}' ); sleep 30 ; kubectl -n $1 get pods --no-headers -o wide ;}
function kcfg() {
if [ $# -eq 0 ]
then
if [ "$KUBECONFIG" != "" ]
then
echo """
###
KUBECONFIG=$KUBECONFIG
###
"""
else
echo """
###
KUBECONFIG empty
###
"""
fi
ls -1tr ~/.kube/configs
else
export KUBECONFIG=$HOME/.kube/configs/$1
fi
}
function k_logs() { k -n $1 logs $(k -n $1 get pods --no-headers | c1 | head -n 1) ; }
function K_PATCH_NS() {
kubectl \
patch ns "$1" \
--type='json' \
-p=$2
}
function K_PATCH_DEPLOYMENT() {
kubectl \
-n "$1" patch deployment "$2" \
--type='json' \
-p=$3
}
function K_GET_DEPLOYMENT_BY_NS() {
kubectl -n "$1" get deployment -o json | jq -r '.items[]|.metadata.name'
}
function K_GET_DEPLOYMENT_LABELS() {
kubectl -n "$1" get deployment -o json | \
jq -r '.items[]|.metadata.labels|to_entries|map("\(.key)=\(.value|tostring)")|.[]'
}
function K_GET_NS_LABELS() {
kubectl get ns "$1" -o json | \
jq -r '.metadata.labels|to_entries|map("\(.key)=\(.value|tostring)")|.[]'
}
function K_GET_NS_WITH_TIMEBOMB() {
if [ $# -eq 1 ]
then
if [ "$1" == "true" ]
then
export TIMEBOMB=NOK
else
export TIMEBOMB=OK
fi
kubectl get ns -o json | \
jq -r '''
.items[]|
.metadata.labels|
{
"name": .name,
"kubeomatic-io-timebomb": (."kubeomatic-io-timebomb" | . |= if .==null then "NOK" else . end),
"kubeomatic-io-timebomb-cluster": (."kubeomatic-io-timebomb-cluster" | . |= if .==null then "NOK" else . end)
} |
select(."kubeomatic-io-timebomb" != "'$TIMEBOMB'")|
[.name,."kubeomatic-io-timebomb-cluster"] | @tsv
''' | column -t
else
echo K_GET_NS_WITH_TIMEBOMB Not enough arguments >&2
fi
}
function K_GET_NS_BY_LABEL() {
if [ $# -eq 3 ]
then
kubectl get ns -A -o json | \
jq -r '''
.items[]|
.metadata|
{
"name": .name,
"'$1'": (.labels."'$1'" | . |= if .==null then "NOK" else . end)
} |
select(."'$1'" '$2' "'$3'")|
[.name,."'$1'"] | @tsv
''' | column -t
else
echo K_GET_NS_BY_LABEL Not enough arguments >&2
fi
}
function K_GET_DEPLOYMENT_BY_LABEL() {
if [ $# -eq 3 ]
then
kubectl get deployments -A -o json | \
jq -r '''
.items[]|
.metadata.labels|
{
"name": .name,
"'$1'": (."'$1'" | . |= if .==null then "NOK" else . end)
} |
select(."'$1'" '$2' "'$3'")|
.metadata|[.namespace,.name] | @tsv
''' | column -t
else
echo K_GET_DEPLOYMENT_BY_LABEL Not enough arguments >&2
fi
}
alias k=kubectl
alias ki="k -n ingress"
alias km="k -n monitoring"
alias ks="k -n kube-system"
# __ __ _
#| \/ (_)___ ___
#| |\/| | / __|/ __|
#| | | | \__ \ (__
#|_| |_|_|___/\___|
#
function JQ_FLAT() { while read -r LINE; do echo $LINE;done | jq -r 'paths(scalars) as $path | { ($path | map(tostring) | join("_")): getpath($path) }| to_entries|map("\(.key)=\(.value|tostring)")|.[]' ; }
function COMPRESS_ENCRYPT() {
for BIN in {pv,pigz,openssl,lscpu,split,tar}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done
if [ $# -ne 3 ] || [ ! -e $2 ] || [ -e $3 ] || [ $(echo $1 | grep ^[0-9]$ | wc -l ) -eq 0 ]
then
echo FAIL
echo COMPRESS_ENCRYPT LEVEL SOURCE DESTINATION
return 1
fi
export LEVEL=$1
export SRC="$2"
export DST="$3"
export ITER=$(expr $(expr $[ $RANDOM % 100 + 10000 ] \* $[ $RANDOM % 10000 + 100 ] + $[ $RANDOM % 10 ]))
export CPUN=$( lscpu| grep "^CPU(s):" | awk '{print $2}')
export SIZE=$(du -sk $SRC| awk '{print $1}')k
mkdir $DST
echo COMPRESS AND ENCRYPT
echo ITER=$ITER
tar cf - $SRC | pv -s $SIZE | pigz -p $CPUN -$LEVEL | openssl aes-256-cbc -iter $ITER -pbkdf2 -salt -e -in - -out - | split -b 256m - "$DST"/bkp
}
function CENSOR() {
coproc stdbuf -o0 sed "s/$1/***/g" &
while read -r LINE
do
echo "$LINE" >&${COPROC[1]}
read -u ${COPROC[0]} msg
echo "$msg"
done
kill $COPROC_PID
}
function CENSOR_BUILD() {
export SECRETSTRING=''
echo $1 | tr ';' '\n' | \
while read SECRET
do
export SECRETSTRING="CENSOR $SECRET | $SECRETSTRING"
echo $SECRETSTRING
done | tail -n 1 | sed -e "s/|$//g"
}
function DU_ALL() {
ls -1a | while IFS=\; read obj ; do du -sk $obj 2>/dev/null;done | sort -n -k1 | awk '{ if ($1 < 1024) print "\033[1;32m"$1"K " $2 "\033[0m" ; else if ( $1 >= 1024 && $1 <= 1048576 ) print "\033[1;34m"$1/1024"M " $2"\033[0m"; else if ($1 > 1048576 ) print "\033[1;31m"$1/1048576"G " $2"\033[0m"}'
}
function SNAPCLEAN() { sudo snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do sudo snap remove "$snapname" --revision="$revision" ;done ; }
function FSTAB_MP() { if [ $# -ne 4 ] ; then echo -e "Example:\nFUNCTION_NAME LV_NAME FS_TYPOE /PATH/TO/FS" ; else echo UUID=$(blkid | grep $1 | awk -F \" '{print $2}') $2 $3 defaults 1 2 ; fi ; }
function ip_range() { seq $2 $3 | while read C; do seq $4 $5 | while read D ; do echo $1.$C.$D ; done;done ; }
function testport() { retorno=$(nc -w 5 -z $1 $2 2>/dev/null; echo $? ) ; if [ $retorno -eq 0 ] ; then echo $retorno $1 $2;fi ; }
function testrange() { seq $2 $3 | while read valor; do testport $1 $valor & done ; }
function ealias() { alias $1 | awk -F \' '{print $2}' ; }
function SSHLOOP() { if [ $# -ne 1 ] ; then echo -n "NOT ENOUGH ARGUMENTS\n$0 SERVERNAME" ; return 1 ; fi; while true; do sshpass -f ~/.ssh/senha ssh -XC -A -o ConnectTimeout=3 $1 ; sleep 1;date;done ; }
function loop() { if [ $# -ne 2 ] ; then echo -n "NOT ENOUGH ARGUMENTS\n$0 \"commands\" seconds" ; return 1 ; fi; while true; do date; bash -c "$1"; sleep $2 ;done ; }
function get_terraform_ips() { find . -type f -name terraform.tfstate -exec grep -w private_ip_address {} \; | awk -F \" '{ print $4} ' | sort -u ; }
function BACKUPNOW () {
for BIN in {pv,split,pigz}; do if [ $(which $BIN | wc -l | awk '{print $1} ') -eq 0 ]; then echo $BIN not found ; return 1; else if [ $(file "$(which $BIN)" 1>&1 >/dev/null;echo $?) -ne 0 ]; then echo $BIN not found; return 1; fi;fi ;done ;
if [ -z $1 ]
then
export THREAD=8
else
export THREAD=$1
fi
if [ -z $2 ]
then
export LEVEL=9
else
export LEVEL=$2
fi
export DATADIR=$(date +"%y%m%d")
export DATAPATH=PATH TO SOMEWHERE
export LIST=$(ls -1a | egrep -v "^OneDrive|^.$|^..$|^Library|^.gradle|^.Trash|^.nuget|^.lima|^Downloads")
export ALLSIZE=$(echo $LIST | while IFS=\; read obj; do du -sk $obj 2>/dev/null;done|awk '{ s = s + $1} END { print s"k"}')
mkdir -p $DATAPATH
echo SIZE= $ALLSIZE, THREAD= $THREAD, LEVEL=$LEVEL
export ITERN=$(expr $(expr $[ $RANDOM % 100 + 100000 ] \* $[ $RANDOM % 10000 + 100 ] + $[ $RANDOM % 10 ]))
tar cf - $(echo $LIST | tr '\n' ' ')2>/dev/null| pv -s $ALLSIZE | pigz -p $THREAD -$LEVEL| openssl aes-256-cbc -iter $ITERN -pbkdf2 -salt -e -in - -out - | split -b 256m - "$DATAPATH"/bkp.
}
function GENPASS() {
#!/bin/bash
if [ $# -eq 2 ]
then
export tamanho=$2
else
export tamanho=13
fi
function HIGH() {
# tr -dc A-Za-z0-9!?@#_ < /dev/urandom | head -c ${tamanho} | xargs
while true
do
export PASSWORD=$(tr -dc 'A-Za-z0-9!?@#_' < /dev/urandom | head -c ${tamanho} | xargs)
if [ $(echo $PASSWORD | sed -e "s/./&\n/g" | egrep "\!|@|#|_|\?" | wc -l ) -gt 2 ] && \
[ $(echo $PASSWORD | sed -e "s/./&\n/g" | grep "[0-9]" | wc -l ) -gt 2 ] && \
[ $(echo $PASSWORD | sed -e "s/./&\n/g" | grep "[a-z]" | wc -l ) -gt 2 ] && \
[ $(echo $PASSWORD | sed -e "s/./&\n/g" | grep "[A-Z]" | wc -l ) -gt 2 ]
then
echo GOOD $PASSWORD
break
else
echo WEAK $PASSWORD
fi
done
}
function MEDIUM() {
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${tamanho} | xargs
}
function LOW() {
tr -dc A-Za-z0-9 < /dev/urandom | head -c ${tamanho} | xargs
}
function NUMBER() {
tr -dc 0-9 < /dev/urandom | head -c ${tamanho} | xargs
}
function HEXA() {
tr -dc A-F0-9 < /dev/urandom | head -c ${tamanho} | xargs
}
function FAKEWWN() {
tr -dc A-F0-9 < /dev/urandom | head -c 16 | xargs | sed -e "s/^0x//g" | sed -r "s/../&:/g" | sed -e "s/$://g" | tr "a-z" "A-Z" | sed -e "s/:$//g"
}
function HELP() {
echo HELP
echo $(echo $0 | tr '\/' '\n' | tail -n 1) \<numero de caracteres\> \| \[ alto \| medio \| baixo \| numero \| hexa \] \<numero de caracteres\>
echo $(echo $0 | tr '\/' '\n' | tail -n 1) \[ alto \| medio \| baixo \| numero \| hexa \| fakewwn\]
echo $(echo $0 | tr '\/' '\n' | tail -n 1) \#Opção default utiliza a complexidade alta com $tamanho caracteres
}
case $1 in
alto)
HIGH
;;
medio)
MEDIUM
;;
baixo)
LOW
;;
numero)
NUMBER
;;
hexa)
HEXA
;;
fakewwn)
FAKEWWN
;;
help)
HELP
;;
ajuda)
HELP
;;
*)
re='^[0-9]+$'
if ! [[ $1 =~ $re ]]
then
export tamanho=13
else
export tamanho=$1
fi
HIGH
;;
esac
}
function TAMANHO() {
ls -1a | while IFS=\; read obj ; do du -sk $obj 2>/dev/null;done | sort -n -k1 | awk '{ if ($1 < 1024) print "\033[1;32m"$1"K " $2 "\033[0m" ; else if ( $1 >= 1024 && $1 <= 1048576 ) print "\033[1;34m"$1/1024"M " $2"\033[0m"; else if ($1 > 1048576 ) print "\033[1;31m"$1/1048576"G " $2"\033[0m"}'
}
alias aA='tr "[a-z]" "[A-Z]"'
alias Aa='tr "[A-Z]" "[a-z]"'
alias c1="awk '{print \$1}'"
alias c2="awk '{print \$2}'"
alias c3="awk '{print \$3}'"
alias c4="awk '{print \$4}'"
alias c5="awk '{print \$5}'"
alias c6="awk '{print \$6}'"
alias c7="awk '{print \$7}'"
alias c8="awk '{print \$8}'"
alias c9="awk '{print \$9}'"
alias c10="awk '{print \$10}'"
alias load_agent="eval $(ssh-agent)"
alias load_key=ssh-add
alias loadall='eval $(ssh-agent);ssh-add'
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
HISTCONTROL=ignoreboth
HISTSIZE=100000000
HISTFILESIZE=200000000
export PS1="%n@%m %1~ %# "
export PS2="%_> "
setopt interactivecomments