Facebook Twitter
Linkedin LJ
Git Instagram
IPv6
5 posts tagged

bash

More .bashrc improvements

I need to see long path and host name. And not to lose command line space at the same time:

BOLD="\[$($TTY  && /usr/bin/tput bold)\]"
COLOR_BLACK="\[$($TTY  && /usr/bin/tput setaf 0)\]"
COLOR_RED="\[$($TTY  && /usr/bin/tput setaf 1)\]"
COLOR_GREEN="\[$($TTY  && /usr/bin/tput setaf 2)\]"
COLOR_YELLOW="\[$($TTY && /usr/bin/tput setaf 3)\]"
COLOR_BLUE="\[$($TTY  && /usr/bin/tput setaf 4)\]"
COLOR_MAGENTA="\[$($TTY  && /usr/bin/tput setaf 5)\]"
COLOR_CYAN="\[$($TTY  && /usr/bin/tput setaf 6)\]"
COLOR_WHITE="\[$($TTY  && /usr/bin/tput setaf 7)\]"
COLOR_GRAY="\[$($TTY  && /usr/bin/tput setaf 8)\]"
RESET="\[$($TTY  && /usr/bin/tput sgr0)\]"



function prompt_command  {     
    local TIMESTAMP="${BOLD}${COLOR_GRAY}\D{%d/%m %H:%M:%S}${RESET}"
    local CURPWD="${BOLD}${COLOR_BLUE}${PWD/#${HOME}/~}${RESET}"

    PS1="\n┌[${BOLD}\u@${COLOR_RED}\h${RESET}]─[${CURPWD}]\n"
    PS1=${PS1}"└─"${TIMESTAMP}${BOLD}"-> "

}

PROMPT_COMMAND=prompt_command
Jan 27   bash   IT   linux
2016   apple   awk   bash   IT

TOC and collapsible block samples

I am writing some tool for my daily work that produces fancy HTML page from RHEL, CentOS or Fedora log and config files, so it would be more easy to read them. Nothing special, just some bash scripts with sed, grep and awk that produce HTML with some CSS and JQuery.

  1. TOC I really liked: http://projects.jga.me/toc/ It’s very easy to use and implement, it just looking through the document for h1, h2, etc tags. Scope and what tags to look can be customized.
  1. Collapsible blocks sample: https://codepen.io/peternguyen/pen/hICga/

May be it would be yet another “log2html” framework in the end.

2016   bash   IT   jquery   js   linux   work

How to sort messages log

If you need to sort out what is reporting to the /var/log/messages to array in case of Red Hat Enterprise Linux or Fedora, you need to do flowing manipulations:

  1. read log;
  2. get 5th column from the log, it’s daemon name;
  3. get rid of all digits, so the daemons with different PIDs would be counted as one;
  4. get rid of all ‘/’ and replace ‘[’ and ‘]’ with ‘\[’ and ‘\]’ to keep things both readable and usable for future scripting;
  5. sort unique stuff.

in my case this gets look like:

cat /var/log/messages | awk '{ print $5 }'| sed 's/\[[0-9].*$//'|sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g'| sed 's/://g' |sed 's/\///g' |sort -u``

the result is usable as array for example. My host’s result:

abrt-hook-ccpp
at-spi-bus-launcher
audit
avahi-daemon
blueman.desktop
blueman-mechanism
bluetoothd
chronyd
cinnamon-killer-daemon
cinnamon-session
com.redhat.imsettings
...
skip
...
tracker-store.desktop
udisksd
usrlibexecgdm-x-session
vmware-user.desktop
wpa_supplicant
2016   awk   bash   centos   fedora   IT   rhel   scripting

Not to forget useful vi and bash settings

.bash_profile

alias opera=opera --disable-remote-fonts
alias grep='grep --color=auto'
alias unigrep='grep -P "[^\x00-\x7F]"'
alias mkdir="mkdir -p"
alias ls='ls -lh --color=auto'
HISTCONTROL=ignoredups:ignorespace
HISTSIZE=100000
HISTFILESIZE=200000

.vimrc

set mouse=r
syntax enable
set tabstop=4
set softtabstop=4
set expandtab
set number
set cursorline
set hlsearch
set incsearch  
set showmatch
nmap <F1> <Esc>:set nonumber<cr>                                                                                                                                             
nmap <F2> <Esc>:set number<cr>
nmap <F5> <Esc>yy<cr>
nmap <F6> <Esc>p<cr>
nmap <F8> <Esc>dd<cr>
nmap <F10> <Esc>:wq!<cr>
nmap <F12> <Esc>:q!<cr>

Not sure about ‘number’ setting, if interferes with the clipboard annoyingly, so I can turn them off.

2016   bash   centos   desktop   linux   vi