My .bashrc: mudanças entre as edições

De Wiki Clusterlab.com.br
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
Linha 89: Linha 89:
function loop() { if [ $# -ne 2 ] ; then echo -n "NOT ENOUGHT ARGUMENTS\n$0 \"commands\" seconds" ; return 1 ; fi; while true; do date; bash -c "$1"; sleep $2 ;done ;  }
function loop() { if [ $# -ne 2 ] ; then echo -n "NOT ENOUGHT 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 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 () {

Edição das 17h57min de 6 de dezembro de 2022

echo Profile Loaded
#    _
#   / \    _____   _ _ __ ___
#  / _ \  |_  / | | | '__/ _ \
# / ___ \  / /| |_| | | |  __/
#/_/   \_\/___|\__,_|_|  \___|
#

function KEYVAULT_SECRET_SET() { 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 KEYVAULT_SECRET_FIND() { cat $1  | jq -r '.[]|.name' | grep -i $2 | while read KEY; do cat $1 | jq -r '.[]|select(.name=="'$KEY'")' ;done ; }

function KEYVAULT_SECRET_LIST() { 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 KEYVAULT_SECRET_SHOW() { 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 KEYVAULT_SECRET_FROM_LIST() { 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 AZURE_GET_VM_IPS() { if [ $# -ne 2 ] ; then echo -e "NOT ENOUGHT 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() { if [ $# -ne 4 ] ; then echo -e "NOT ENOUGHT 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() {  if [ $# -ne 4 ] ; then echo -e "\nNOT ENOUGHT 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() { figlet $1 | sed -e "s/^/\#/g" ; }

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_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) ; }

alias k=kubectl
alias ki="k -n ingress"
alias km="k -n monitoring"
alias ks="k -n kube-system"
# __  __ _
#|  \/  (_)___  ___
#| |\/| | / __|/ __|
#| |  | | \__ \ (__
#|_|  |_|_|___/\___|
#
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 ENOUGHT 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 ENOUGHT 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 () {
    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
    tar cf - $(echo $LIST  | tr '\n' ' ')2>/dev/null| pv -s $ALLSIZE | pigz -p $THREAD -$LEVEL | split -b 256m - "$DATAPATH"/bkp.
}

function GENPASS() {
    while true
    do
        export PASSWORD=$(tr -dc 'A-Za-z0-9!?@#_' < /dev/urandom | head -c 16 | xargs) ;
        # echo $PASSWORD
        if [[ $(echo $PASSWORD | egrep "\!|@|#|_|\?"  | sed -e "s/./&\n/g" | wc -l ) -ne 0 &&  $(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
            break
        fi
    done
    echo $PASSWORD
}

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