Forked from ysaotome/update_motd_by_screenfetch.sh
Last active
August 29, 2015 14:23
-
-
Save snickerjp/c6e0f197714ef7947380 to your computer and use it in GitHub Desktop.
/etc/motdにサーバ情報を書き込むスクリプト! forked from ysaotome/update_motd_for_centos.sh
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 CentOS | |
# 2013/07/15 @ysaotome | |
# Original from https://gist.github.com/ysaotome/5997652 | |
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_HEAD='/bin/head' | |
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_HEAD} -1 /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
Setup