linux:bash

This is an old revision of the document!


 PS bash/zsh ${SSH_CLIENT+ssh:}${(%):-%m} 
 
# see to set options https://github.com/ricbra/zsh-config/blob/master/zshrc
setopt no_share_history
setopt histignorespace
setopt histignorealldups
setopt histreduceblanks

bash

# to save some commmand
savecmd () {
  echo "$1" >> /tmp/$(date +%F).txt
}
# using 
savecmd "ansible  proxmox -m apt -a "name=qemu-guest-agent    state=present" --become"

Jshon - bash json parser - http://kmkeen.com/jshon/

# Example пример создания - ниже конструирования объектов
jshon -n {}
  -n {}
    -n {}
      -n {}
        -s "ssh" -i ansible_connection
        -s "ubuntu" -i ansible_user
      -i "10.59.4.11"
    -i "hostvars"
  -i "_meta"
  -n {}
    -n []
      -s "10.59.4.11" -i 0
    -i "hosts"
  -i dockers
    
# результат в виде запускаемой строки
 jshon -n {} -n {} -n {} -n {} -s "ssh" -i ansible_connection -s "ubuntu" -i ansible_user -i "10.59.4.11" -i "hostvars" -i "_meta" -n {} -n [] -s "10.59.4.11" -i 0 -i "hosts" -i dockers
# Get process using swap 
$ (echo "COMM:PID:SWAP"; for file in /proc/**/status ; do awk '/^Pid|VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | grep kB | grep -wv "0 kB" | sort -k 3 -n -r ) | column -t | head -50
# Asing heredoc to variable Use $() to assign the output of cat to your variable like this:
VAR=$(cat <<'END_HEREDOC'
test 'test"
$(dont-execute-this)
test"test"''
END_HEREDOC
)
 
# this will echo variable with new lines intact
echo "$VAR"
# this will echo variable without new lines (changed to space character)
echo $VAR
Making sure to delimit starting END_HEREDOC with single-quotes.
# SWAP INFO
alias swapi=$(cat <<'END_HEREDOC'
( echo "COMM:PID:SWAP"; for file in /proc/**/status ; do awk '/^Pid|VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | grep kB | grep -wv "0 kB" | sort -k 3 -n -r ) | column -t | head -50
END_HEREDOC
)
# find KVM and name of kvm names
 ps axf | grep -oE "(64353|930818|182162|239596|804199|692833|64644|309148|126991).+debug" | grep -Eo " guest=\S+"
# Grep exclude comments and blank lines
grep -v '^\s*$\|^\s*\#' temp
  • linux/bash.1601660037.txt.gz
  • Last modified: 2020/10/02 17:33
  • by admin