Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/etc/motdにサーバ情報を書き込むスクリプト。cronとかで回しておくと便利。#Ubuntu(http://manpages.ubuntu.com/manpages/lucid/man5/update-motd.5.html) やAmazonLinuxみたいなupdate-motdがCentOSにも欲しい。
#!/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}
#!/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}
@ysaotome

This comment has been minimized.

Show comment Hide comment
@ysaotome

ysaotome Jul 14, 2015

example

setup for update_motd_for_figlet.sh

Imgur

/usr/bin/yum --enablerepo=epel -y install figlet

/usr/bin/wget --no-check-certificate -P /usr/local/bin/ 'https://gist.githubusercontent.com/ysaotome/5997652/raw/update_motd_by_figlet.sh'
/bin/chmod 755 /usr/local/bin/update_motd_by_figlet.sh
/usr/local/bin/update_motd_by_figlet.sh
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd
#update-moted
*/5 * * * * root /usr/local/bin/update_motd_by_figlet.sh
_UPDATEMOTD_

setup for update_motd_by_screenfetch.sh

Imgur

/usr/bin/wget --no-check-certificate -O /usr/local/bin/screenfetch https://raw.githubusercontent.com/KittyKatt/screenFetch/master/screenfetch-dev
/bin/chmod 755 /usr/local/bin/screenfetch

/usr/bin/wget --no-check-certificate -P /usr/local/bin/ 'https://gist.github.com/ysaotome/5997652/raw/fecdf757b348debfcdd866df00f6d567ff749623/update_motd_by_screenfetch.sh'
/bin/chmod 755 /usr/local/bin/update_motd_by_screenfetch.sh
/usr/local/bin/update_motd_by_screenfetch.sh
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd
#update-moted
*/5 * * * * root /usr/local/bin/update_motd_by_screenfetch.sh
_UPDATEMOTD_
Owner

ysaotome commented Jul 14, 2015

example

setup for update_motd_for_figlet.sh

Imgur

/usr/bin/yum --enablerepo=epel -y install figlet

/usr/bin/wget --no-check-certificate -P /usr/local/bin/ 'https://gist.githubusercontent.com/ysaotome/5997652/raw/update_motd_by_figlet.sh'
/bin/chmod 755 /usr/local/bin/update_motd_by_figlet.sh
/usr/local/bin/update_motd_by_figlet.sh
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd
#update-moted
*/5 * * * * root /usr/local/bin/update_motd_by_figlet.sh
_UPDATEMOTD_

setup for update_motd_by_screenfetch.sh

Imgur

/usr/bin/wget --no-check-certificate -O /usr/local/bin/screenfetch https://raw.githubusercontent.com/KittyKatt/screenFetch/master/screenfetch-dev
/bin/chmod 755 /usr/local/bin/screenfetch

/usr/bin/wget --no-check-certificate -P /usr/local/bin/ 'https://gist.github.com/ysaotome/5997652/raw/fecdf757b348debfcdd866df00f6d567ff749623/update_motd_by_screenfetch.sh'
/bin/chmod 755 /usr/local/bin/update_motd_by_screenfetch.sh
/usr/local/bin/update_motd_by_screenfetch.sh
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd
#update-moted
*/5 * * * * root /usr/local/bin/update_motd_by_screenfetch.sh
_UPDATEMOTD_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment