Add some aliases and functions
Signed-off-by: Alban VIDAL <alban.vidal@zordhak.fr>
This commit is contained in:
parent
024ee9f826
commit
cd2a8d7ed8
@ -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`
|
||||
|
@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# BSD 3-Clause License
|
||||
#
|
||||
# Copyright (c) 2018, Alban Vidal <alban.vidal@zordhak.fr>
|
||||
@ -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/
|
||||
|
||||
|
14
root/.bashrc
14
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 '
|
||||
|
@ -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
|
||||
|
32
root/.profile.d/00_functions.conf
Normal file
32
root/.profile.d/00_functions.conf
Normal file
@ -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
|
||||
}
|
@ -1 +0,0 @@
|
||||
echo TODO
|
43
root/.profile.d/01_stats_connexion.conf
Normal file
43
root/.profile.d/01_stats_connexion.conf
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user