Speaking of MOTD, the students familiar with Linux system should be familiar with, MOTD it is a common file on Linux system,/ETC/MOTD file on Linux system. Action: Each time the system needs to log in, display some messages to the login user through the terminal.
However, by in the MOTD file, the added message can only be static, the function is not intuitive, also not dazzle, in order to achieve these effects, it is necessary to make a dynamic MOTD information effect, this section Jeson teach you how to make a dynamic MOTD landing effect.
1. Make a login logo
In fact, is to use some good-looking symbols to splice, Jeson production of the following (my blog logo), we use VIM to create a new empty file Login_logo.txt, edit and save. We should:
(1) Logo as simple and clear as possible, not complicated
(2) If you do not want to design, then copy someone else's bar, here to provide you with a Web site to reference.
_ (_) _ _ __ ___ __ __ __ __ ‘_ ` _ \ / \ / \ / / / / __ _ _ \__/ \__/ \_\ \_\
2. Shell scripts
Write a shell script to complete the creation of the dynamic message content.
I wrote the following, for your reference:
########################################################################## File Name:/opt/work/test/login_bash_ok.sh# program Function:# Author:jeson# Mail:[email Protected]# Created Time: 410/6 10:41:58 2016# * VariablesUser=$USERpath=$PWDhome=$HOME# * Check If we ' re somewhere in/homeIf [ ! -D ${Home} ];Then Return 0Fi# * Calculate Last LoginLastlog=' Lastlog-u ${user}grep ${user}awk ' {for (i=3;i<=nf;++i) printf ('%s ', $i)} '## * ASCII HeadCat/Opt/Work/Login_logo.Txt# * Print OutputEcho":::::::::":::-: "::::--":::::: "::"::::::::::::::::::::::::::::::::::::::::::::::Reset_terminal=$(Tput sgr0)# * Check RAM and SWAP UsagesApp_mem_usages=$(Awk'/memtotal/{total=$2}/memfree/{free=$2}/buffers/{buffers=$2}/^cached/{cached=$2}end{print ( total-free-buffers-cached)/1024} ' /Proc/Meminfo)Echo-E' \e[32m ' "Application memmory Usages:"$reset _terminal ${App_mem_usages}All_mem_usages=$(Awk'/memtotal/{total=$2}/memfree/{free=$2}end{print (total-free)/1024} ' /Proc/Meminfo)Echo-E' \e[32m ' "System memmory Usages:"$reset _terminal ${All_mem_usages}# * Check Disk UsagesDisk_device=$(Fdisk-LgrepDiskgrep -Ve' identifier 'Grep-IoE' \/dev\/[a-z]{2} 'Uniq)Diskusages=$(Df-PH grep-Ve' ^filesystemtmpfscdrom 'Awk' {print $ ' "$")Echo-e ' \e[32m ' "Disk Usages:" $reset _terminal ${diskusages}# * Check Load averageloadaverage=$ ( top -n 1-b grep "load average:" awk ' {print $ (NF-2) $ (NF-1) $NF} ' ) echo -e ' \e[32m ' "" ])])]] ">) }
After the modification, perform the check output is normal
3. Modify the Configuration
If you want to specify that a user is logged in and then executed and generated, you need to add the command that executes the script to the ~/.BASHRC file.
[Email protected] ~]$ vim ~/.BASHRC
To join the execution statement:
sh/opt/work/login_bash.sh
In addition, if you want to be a global user, then you need to join the/ETC/BASHRC configuration.
4. Verification
1) exit the current landing terminal
2) with the designated user login, if there appears in this note before the login information, then the successful completion.
Linux needs to be installed? Then come with me. Configure a dynamic MOTD landing effect.