Quantcast
Channel: DJRavine's Codebook » Linux
Viewing all articles
Browse latest Browse all 7

BASH – .bash_profile – Custom Login Message with Colours

$
0
0

Hey all,

I have made a few customisations to my dedicated server over the years, one of which is a custom login message with a full coloured display.

I have posted the code below for you all to inspect and use at your own discretion.

Have fun all!

Custom .bash_profile

Custom .bash_profile

 

# .bash_profile

# Custom Command Prompt
export PS1="\n\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]\n$ "

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/sbin
export PATH
unset USERNAME
umask u=rwx,g=rwx,o=

# Custom DJRavine Modification

login_pwd='pwd';
login_date='date';
login_users='users';
login_uptime='uptime';
server_ip="ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'";
disk_available=$(df -h --block-size=1024 | awk '{sum += $4;} END {print sum;}');
disk_used=$(df -h --block-size=1024 | awk '{sum += $3;} END {print sum;}');
disk_size=$(df -h --block-size=1024 | awk '{sum += $2;} END {print sum;}');
disk_available_mb=$(echo "scale=2; $disk_available/(1024^2)" | bc)
disk_used_mb=$(echo "scale=2; $disk_used/(1024^2)" | bc)
disk_size_mb=$(echo "scale=2; $disk_size/(1024^2)" | bc)

open_red_escape="\033[31m"
open_blue_escape="\033[34m"
open_green_escape="\033[32m"
close_escape="^\033[0m"

echo -e " "
echo -e "${open_blue_escape}+----------------------------------------------------------------------"
echo -e "${open_blue_escape}| "
echo -e "${open_blue_escape}| ${open_green_escape}          _    _       _    _                            "
echo -e "${open_blue_escape}| ${open_green_escape}         | |  | |     | |  | |       Welcome To          "
echo -e "${open_blue_escape}| ${open_green_escape}         | |  | | ___ | |  | |_ __  ___   ___  _ __ __ _ "
echo -e "${open_blue_escape}| ${open_green_escape}         | |/\| |/ _ \| |/\| | '_ \/ __| / _ \| '__/ _` |"
echo -e "${open_blue_escape}| ${open_green_escape}         \  /\  / (_) \  /\  / |_) \__ \| (_) | | | (_| |"
echo -e "${open_blue_escape}| ${open_green_escape}          \/  \/ \___/ \/  \/| .__/|___(_)___/|_|  \__, |"
echo -e "${open_blue_escape}| ${open_green_escape}                             | |                    __/ |"
echo -e "${open_blue_escape}| ${open_green_escape}                             |_|                   |___/ "
echo -e "${open_blue_escape}|"
echo -e "${open_blue_escape}+----------------------------------------------------------------------"
echo -e "${open_blue_escape}| ${open_green_escape}Server IP: ${open_red_escape}"$server_ip
echo -e "${open_blue_escape}| ${open_green_escape}Date: ${open_red_escape}"$login_date
echo -e "${open_blue_escape}| ${open_green_escape}Users: ${open_red_escape}"$login_users
echo -e "${open_blue_escape}| ${open_green_escape}Directory: ${open_red_escape}"$login_pwd
echo -e "${open_blue_escape}| ${open_green_escape}Uptime: ${open_red_escape}"$login_uptime
echo -e "${open_blue_escape}+----------------------------------------------------------------------${open_green_escape}"
df -h  | column -c 6 | awk '{ printf "\033[22;34m| \033[22;32m%s\t%s\t\033[22;31m%s\t%s\t%s\n", $1, $6, $2, $3, $4,$5 }'

echo -e "${open_blue_escape}| ${open_green_escape}Total Disk Space: ${open_red_escape}${disk_size_mb} GB"
echo -e "${open_blue_escape}| ${open_green_escape}Total Free Space: ${open_red_escape}${disk_available_mb} GB"
echo -e "${open_blue_escape}| ${open_green_escape}Total Used Space: ${open_red_escape}${disk_used_mb} GB"
echo -e "${open_blue_escape}+----------------------------------------------------------------------"
echo -e " "


Viewing all articles
Browse latest Browse all 7

Trending Articles