Last active
March 4, 2021 13:29
-
-
Save ysaotome/5997652 to your computer and use it in GitHub Desktop.
/etc/motdにサーバ情報を書き込むスクリプト。cronとかで回しておくと便利。#Ubuntu(http://manpages.ubuntu.com/manpages/lucid/man5/update-motd.5.html) やAmazonLinuxみたいなupdate-motdがCentOSにも欲しい。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Description:UpdateMotd by screenFetch | |
# References: http://goo.gl/xpWV7L | |
# 2015/07/08 @ysaotome | |
FILE_MOTD='/etc/motd' | |
BIN_DATE='/bin/date' | |
BIN_FIGLET='/usr/bin/figlet' | |
BIN_HOSTNAME='/bin/hostname' | |
BIN_IP='/sbin/ip' | |
BIN_GREP='/bin/grep' | |
BIN_SED='/bin/sed' | |
BIN_UPTIME='/usr/bin/uptime' | |
BIN_CAT='/bin/cat' | |
BIN_UNAME='/bin/uname' | |
BIN_FREE='/usr/bin/free' | |
BIN_HEAD='/usr/bin/head' | |
BIN_TAIL='/usr/bin/tail' | |
BIN_DF='/bin/df' | |
BIN_AWK='/bin/awk' | |
BIN_BC='/usr/bin/bc' | |
BIN_PS='/bin/ps' | |
BIN_SCREENFETCH='/usr/local/bin/screenfetch' | |
COLOR_LIGHT_GREEN='\033[1;32m' | |
COLOR_LIGHT_BLUE='\033[1;34m' | |
COLOR_YELLOW='\033[1;33m' | |
COLOR_RED='\033[0;31m' | |
COLOR_WHITE='\033[1;37m' | |
COLOR_DEFAULT='\033[0m' | |
echo -e " | |
$(${BIN_SCREENFETCH}) | |
" > ${FILE_MOTD} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Description:UpdateMotd for Figlet | |
# 2013/07/15 @ysaotome | |
FILE_MOTD='/etc/motd' | |
BIN_DATE='/bin/date' | |
BIN_FIGLET='/usr/bin/figlet' | |
BIN_HOSTNAME='/bin/hostname' | |
BIN_IP='/sbin/ip' | |
BIN_GREP='/bin/grep' | |
BIN_SED='/bin/sed' | |
BIN_UPTIME='/usr/bin/uptime' | |
BIN_CAT='/bin/cat' | |
BIN_UNAME='/bin/uname' | |
BIN_FREE='/usr/bin/free' | |
BIN_HEAD='/usr/bin/head' | |
BIN_TAIL='/usr/bin/tail' | |
BIN_DF='/bin/df' | |
BIN_AWK='/bin/awk' | |
BIN_BC='/usr/bin/bc' | |
BIN_PS='/bin/ps' | |
COLOR_LIGHT_GREEN='\033[1;32m' | |
COLOR_LIGHT_BLUE='\033[1;34m' | |
COLOR_YELLOW='\033[1;33m' | |
COLOR_RED='\033[0;31m' | |
COLOR_WHITE='\033[1;37m' | |
COLOR_DEFAULT='\033[0m' | |
echo -e " | |
${COLOR_LIGHT_GREEN}$(${BIN_FIGLET} -ckw 120 -f slant $(${BIN_HOSTNAME})) | |
${COLOR_WHITE}Motd Updated : ${COLOR_LIGHT_BLUE}$(${BIN_DATE}) | |
${COLOR_WHITE}Hostname = ${COLOR_LIGHT_BLUE}$(${BIN_HOSTNAME}) | |
${COLOR_WHITE}Global IP Address = ${COLOR_LIGHT_BLUE}$(${BIN_IP} addr show eth0 2>/dev/null | ${BIN_GREP} 'inet ' | ${BIN_SED} -e 's/.*inet \([^ ]*\)\/.*/\1/') | |
${COLOR_WHITE}Privte IP Address = ${COLOR_LIGHT_BLUE}$(${BIN_IP} addr show eth1 2>/dev/null | ${BIN_GREP} 'inet ' | ${BIN_SED} -e 's/.*inet \([^ ]*\)\/.*/\1/') | |
${COLOR_WHITE}Uptime = ${COLOR_LIGHT_BLUE}$(${BIN_UPTIME} | ${BIN_SED} -e 's/^ //') | |
${COLOR_WHITE}Release = ${COLOR_LIGHT_BLUE}$(${BIN_CAT} /etc/issue.net) | |
${COLOR_WHITE}Kernel = ${COLOR_LIGHT_BLUE}$(${BIN_UNAME} -orpi) | |
${COLOR_WHITE}CPU Usage (Core) = ${COLOR_LIGHT_BLUE}$(echo $(${BIN_PS} -eo pcpu | ${BIN_AWK} 'NR>1' | ${BIN_AWK} '{tot=tot+$1} END {print tot}') / $(${BIN_CAT} /proc/cpuinfo | ${BIN_GREP} -c processor) | ${BIN_BC} )% | |
${COLOR_WHITE}Memory Used/Total = ${COLOR_LIGHT_BLUE}$(${BIN_FREE} -m | ${BIN_HEAD} -n 2 | ${BIN_TAIL} -n 1 | ${BIN_AWK} {'print $3'})/$(${BIN_FREE} -m | ${BIN_HEAD} -n 2 | ${BIN_TAIL} -n 1 | ${BIN_AWK} {'print $2'})MB | |
${COLOR_WHITE}Swap Used/Total = ${COLOR_LIGHT_BLUE}$(${BIN_FREE} -m | tail -n 1 | ${BIN_AWK} {'print $3'})/$(${BIN_FREE} -m | ${BIN_TAIL} -n 1 | ${BIN_AWK} {'print $2'})MB | |
${COLOR_WHITE}Disk(/) Used/Total = ${COLOR_LIGHT_BLUE}$(${BIN_DF} -h / | tail -n 1 | ${BIN_AWK} {'print $3'})/$(${BIN_DF} -h / | ${BIN_TAIL} -n 1 | ${BIN_AWK} {'print $2'}) | |
" > ${FILE_MOTD} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example
setup for update_motd_for_figlet.sh
setup for update_motd_by_screenfetch.sh