diff --git a/README.md b/README.md index f71cb27..aa9f343 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,10 @@ git clone https://github.com/AlbanVidal/basic_config_debian.git /srv/git/basic_c cd /srv/git/basic_config_debian ./auto_config.sh ``` + +## New aliases and functions available + ++ `hddtop`: print hard drive usage ++ `ipa`, `ip4a`, `ip6a` and `ip4all`: print interfaces list ++ `memtop`: print top usage memory ++ `jf`: aliases for `journalctl -f` diff --git a/auto_config.sh b/auto_config.sh index 89f9a0d..d053ee9 100755 --- a/auto_config.sh +++ b/auto_config.sh @@ -1,6 +1,5 @@ #!/bin/bash -# # BSD 3-Clause License # # Copyright (c) 2018, Alban Vidal @@ -115,6 +114,7 @@ apt-get -y install \ git \ tig \ bash-completion \ + bsdmainutils \ unattended-upgrades \ apt-listchanges \ logrotate > /dev/null @@ -148,7 +148,8 @@ ln -sf $GIT_DIR/root/.bashrc /root/ # Profile ln -sf $GIT_DIR/root/.profile /root/ mkdir -p /root/.profile.d -ln -sf $GIT_DIR/root/.profile.d/00_stats_connexion.conf /root/.profile.d/ +ln -sf $GIT_DIR/root/.profile.d/00_functions.conf /root/.profile.d/ +ln -sf $GIT_DIR/root/.profile.d/01_stats_connexion.conf /root/.profile.d/ # vimrc ln -sf $GIT_DIR/root/.vimrc /root/ diff --git a/root/.bashrc b/root/.bashrc index 60c71c6..6a6aff6 100644 --- a/root/.bashrc +++ b/root/.bashrc @@ -11,10 +11,12 @@ alias ls='ls -h' alias ll='ls -lh' alias l='ls -lAh' +# Some more alias to avoid making mistakes: alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' +# Color grep alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' @@ -35,8 +37,18 @@ alias gp="git push origin master" alias gl="git log" alias gll="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" +# Network +alias ipa='ip -color addr show' +alias ip4a='ip -4 -color addr show' +alias ip6a='ip -6 -color addr show' + # PS1 -export PS1="\[\033]0;\u@\h - \w\007\]\[\e[32m\]root@\h\[\e[0m\] [\[\e[0m\]\t\[\e[0m\]][\[\e[34m\]\w\[\e[0m\]]$ " +case $(systemd-detect-virt) in + "qemu") PS1_COLOR="34m";; # Blue + "lxc") PS1_COLOR="33m";; # Orange + *) PS1_COLOR="32m";; # Green +esac +export PS1="\[\033]0;\u@\h - \w\007\]\[\e[$PS1_COLOR\]root@\h\[\e[0m\] [\[\e[0m\]\t\[\e[0m\]][\[\e[34m\]\w\[\e[0m\]]$ " # History format HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S ' diff --git a/root/.profile b/root/.profile index 6ac3361..2447ece 100644 --- a/root/.profile +++ b/root/.profile @@ -11,8 +11,9 @@ mesg n # My conf # if .profile.d directory exist, load .conf files -if [ -f ~/.profile.d/*.conf ] ;then - for profile_d_file in /root/.profile.d/*.conf +#if [ -f ~/.profile.d/*.conf ] ;then +if [ -d ~/.profile.d/ ] ;then + for profile_d_file in ~/.profile.d/*.conf do . $profile_d_file done diff --git a/root/.profile.d/00_functions.conf b/root/.profile.d/00_functions.conf new file mode 100644 index 0000000..34a5ea4 --- /dev/null +++ b/root/.profile.d/00_functions.conf @@ -0,0 +1,32 @@ + +# Hard Drive usage +function hddtop() { + df -TPh \ + | grep -E '(^/dev|^ealf)' \ + | sort -k 6,6 -n \ + | awk \ + -v red="$(tput setaf 1)" \ + -v yellow="$(tput setaf 3)" \ + -v green="$(tput setaf 2)" \ + -v reset="$(tput sgr0)" \ + '{printf OFS"%s %s %s %s %s %s %s %s %s\n", \ + (+$6>90)?red:(+$6>80?yellow:green),$1,$2,$3,$4,$5,$6,$7,reset \ + }' \ + | column -t +} + +# List all ip's v4 +ip4all () { + ip -4 -o addr \ + | grep -v 127.0.0 \ + | awk -v blue="$(tput bold;tput setaf 4)" -v reset="$(tput sgr0)" '{printf "%s\t%s\t%s %s %s\n",$2,":",blue,$4,reset}' +} + +# Show top usage memory +function memtop () { + ps -eo size,pid,user,command --sort -size \ + | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x <=NF ;x++ ) { printf("%s ",$x) } print ""}' \ + | cut -d "" -f2 \ + | cut -d "-" -f1 \ + | head -20 +} diff --git a/root/.profile.d/00_stats_connexion.conf b/root/.profile.d/00_stats_connexion.conf deleted file mode 100644 index 483708e..0000000 --- a/root/.profile.d/00_stats_connexion.conf +++ /dev/null @@ -1 +0,0 @@ -echo TODO diff --git a/root/.profile.d/01_stats_connexion.conf b/root/.profile.d/01_stats_connexion.conf new file mode 100644 index 0000000..5c4f613 --- /dev/null +++ b/root/.profile.d/01_stats_connexion.conf @@ -0,0 +1,43 @@ + +date=`date +"%Y-%m-%d - %T"` + +# LOAD AVERAGE + +load=$(cat /proc/loadavg |awk -v red="$(tput setaf 1)" -v yellow="$(tput setaf 3)" -v green="$(tput setaf 2)" -v reset="$(tput sgr0)" '{printf "%s%s%s\n", (+$1>1?red:(+$1>0.7)?yellow:green), $1, reset}') + +# CALCULATE SWAPINESS FOR MEMOIRE ET SWAP + +swapiness=`sysctl vm.swappiness |awk '{print $3}'` +(( swapiness = 100 - swapiness)) +(( mi_swapiness = swapiness / 2 )) + +# MEMORY + +memory_usage=$(free -m| grep 'Mem' |awk ' {total=$2} {avalaible=$7} END { printf("%3.1f%%", 100-avalaible/total*100)}' |awk -v red="$(tput setaf 1)" -v yellow="$(tput setaf 3)" -v green="$(tput setaf 2)" -v reset="$(tput sgr0)" '{printf "%s%s%s\n", (+$1>'$swapiness'?red:(+$1>'$mi_swapiness')?yellow:green), $1, reset}') + +# SWAP + +swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'` +var4=${swap_usage%.*} +((var4 >= 1 )) && swap_usage="\033[31m$swap_usage\033[00m" || swap_usage="\033[32m$swap_usage\033[00m" + +# USERS AND OTHERS + +users=`users | wc -w` +processes=`ps aux | wc -l` + +############# SHOW ############# + +echo +echo -e "OS\t:\t `lsb_release -d | sed -e 's/Description://g' | sed 's/^[ \t]*//'`" +echo -e "Uptime\t:\t $(uptime -p)" +ip4all +echo +hddtop +echo +echo -e "CPU Load\t:\t$load" +echo -e "Memory usage\t:\t$memory_usage" +echo -e "Swap usage\t:\t$swap_usage" +echo -e "Process number\t:\t$processes" +echo +