Fungsi awal untuk tampilan MOTD

master
Ronggo Radityo 2018-09-25 19:55:16 +07:00
parent 7ea00889a0
commit 1d898c7a21
6 changed files with 151 additions and 41 deletions

View File

@ -1,56 +1,28 @@
galaxy_info: galaxy_info:
author: your name author: Ronggo Radityo
description: your description description: Atur MOTD
company: your company (optional) company: Kota Magelang
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker # issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses: license: license (BSD, MIT)
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2 min_ansible_version: 1.2
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
# #
# platforms is a list of platforms, and each platform has a name and a list of versions. # platforms is a list of platforms, and each platform has a name and a list of versions.
# #
# platforms: platforms:
# - name: Fedora - name: Debian
# versions: versions:
# - all - 8
# - 25 - 9
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: [] galaxy_tags:
# List tags for your role here, one per line. A tag is a keyword that describes - linux
# and categorizes the role. Users find roles by searching for tags. Be sure to - debian
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: [] dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above, # List your role dependencies here, one per line. Be sure to remove the '[]' above,

View File

@ -1,2 +1,25 @@
--- ---
# tasks file for roles/motd # tasks file for roles/motd
- name: MOTD - set motd
template:
src: templates/etc/motd.j2
dest: /etc/motd
mode: 0644
- name: MOTD - set motd banner
template:
src: templates/etc/update-motd.d/20-banner.j2
dest: /etc/update-motd.d/20-banner
mode: 0755
- name: MOTD - set system info
template:
src: templates/etc/update-motd.d/30-sysinfo.j2
dest: /etc/update-motd.d/30-sysinfo
mode: 0755
- name: MOTD - set free disk space
template:
src: templates/etc/update-motd.d/40-disks.j2
dest: /etc/update-motd.d/40-disks
mode: 0755

View File

@ -0,0 +1,9 @@
===========================================================
= Disediakan oleh Diskominsta Kota Magelang. =
= =
= Untuk info lebih lanjut, hubungi : =
= Telp : 0293-360990 =
= eMail: admin@magelangkota.go.id =
===========================================================

View File

@ -0,0 +1,36 @@
#!/bin/bash
# Reset
Color_Off=$(printf '\033[0m') # Text Reset
# Bold
BBlack=$(printf '\033[1;30m') # Black
BRed=$(printf '\033[1;31m') # Red
BGreen=$(printf '\033[1;32m') # Green
BYellow=$(printf '\033[1;33m') # Yellow
BBlue=$(printf '\033[1;34m') # Blue
BPurple=$(printf '\033[1;35m') # Purple
BCyan=$(printf '\033[1;36m') # Cyan
BWhite=$(printf '\033[1;37m') # White
# Bold High Intensty
BIBlack=$(printf '\033[1;90m') # Black
BIRed=$(printf '\033[1;91m') # Red
BIGreen=$(printf '\033[1;92m') # Green
BIYellow=$(printf '\033[1;93m') # Yellow
BIBlue=$(printf '\033[1;94m') # Blue
BIPurple=$(printf '\033[1;95m') # Purple
BICyan=$(printf '\033[1;96m') # Cyan
BIWhite=$(printf '\033[1;97m') # White
echo
echo -e "${BRed},---. ,---.${BYellow} ____ ${BGreen} .-${BIYellow}_${BGreen}'''-. ${BBlue} .-''-. ${BWhite} .---. ${BPurple} ____ ${BYellow},---. .--.${BRed} .-${BIYellow}_${BRed}'''-. "
echo -e "${BRed}| \ / |${BYellow} .' __ \`.${BGreen} '${BIYellow}_( )_${BGreen} \ ${BBlue} .'${BIWhite}_ _ ${BBlue} \ ${BWhite} | ${BIPurple},_${BWhite}| ${BPurple} .' __ \`. ${BYellow}| \ | |${BRed} '${BIYellow}_( )_${BRed} \ "
echo -e "${BRed}| , \/ , |${BYellow}/ ' \ \\${BGreen}|${BIYellow}(_ o _)${BGreen}| ' ${BBlue} / ${BIWhite}( \` )${BBlue} '${BIPurple},-./ ) ${BPurple} / ' \ \\${BYellow}| , \ | |${BRed}|${BIYellow}(_ o _)${BRed}| ' "
echo -e "${BRed}| |\\${BIYellow}_ ${BRed} /| |${BYellow}|___| / |${BGreen}. ${BIYellow}(_,_)${BGreen}/___| ${BBlue}. ${BIWhite}(_ o _)${BBlue} |${BIPurple}\ '_ '\`) ${BPurple} |___| / |${BYellow}| |\\${BICyan}_${BYellow} \| |${BRed}. ${BIYellow}(_,_)${BRed}/___| "
echo -e "${BRed}| ${BIYellow} _( )_${BRed}/ | |${BYellow} _.-\` |${BGreen}| | .-----.${BBlue}| ${BIWhite}(_,_)${BBlue}___|${BIPurple} > (_) ) ${BPurple} _.-\` |${BYellow}| ${BICyan}_( )_${BYellow}\ |${BRed}| | .-----. "
echo -e "${BRed}| ${BIYellow}(_ o _)${BRed} | |${BYellow}.' ${BICyan}_${BYellow} |${BGreen}' \ '- .''${BBlue} \ .---.${BIPurple}( . .-' ${BPurple} .' ${BIRed}_${BPurple} |${BYellow}| ${BICyan}(_ o _)${BYellow} |${BRed}' \ '- .' "
echo -e "${BRed}| ${BIYellow} (_,_)${BRed} | |${BYellow}| ${BICyan}_( )_${BYellow} |${BGreen} \ \`-'\` |${BBlue} \ \`-' /${BIPurple} \`-'\`-'${BWhite}|___ ${BPurple}| ${BIRed}_( )_${BPurple} |${BYellow}| ${BICyan}(_,_)${BYellow}\ |${BRed} \ \`-'\` | "
echo -e "${BRed}| | | |${BYellow}\ ${BICyan}(_ o _)${BYellow} /${BGreen} \ / ${BBlue} \ / ${BWhite} | \\${BPurple}\\ ${BIRed}(_ o _)${BPurple} /${BYellow}| | | |${BRed} \ / "
echo -e "${BRed}'--' '--'${BYellow} '.${BICyan}(_,_)${BYellow}.' ${BGreen} \`'-...-' ${BBlue} \`'-..-' ${BWhite} \`--------\`${BPurple} '.${BIRed}(_,_)${BPurple}.' ${BYellow}'--' '--'${BRed} \`'-...-' ${Color_Off}"
echo

View File

@ -0,0 +1,29 @@
#!/bin/bash
# get load averages
IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }')
# get free memory
IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'})
# get processes
PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'`
PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}`
PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
# get processors
PROCESSOR_NAME=`grep "model name" /proc/cpuinfo | cut -d ' ' -f3- | awk {'print $0'} | head -1`
PROCESSOR_COUNT=`grep -ioP 'processor\t:' /proc/cpuinfo | wc -l`
W="\e[0;39m"
G="\e[1;32m"
echo -e "
${W}system info:
$W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'`
$W Kernel......: $W`uname -sr`
$W Uptime......: $W`uptime -p`
$W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m)
$W Processes...:$W $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user), $G$PROCESS_ALL$W (total)
$W CPU.........: $W$PROCESSOR_NAME ($G$PROCESSOR_COUNT$W vCPU)
$W Memory......: $G$USED$W used, $G$FREE$W free, $G$TOTAL$W total$W"

View File

@ -0,0 +1,41 @@
#!/bin/bash
# config
max_usage=90
bar_width=50
# colors
white="\e[39m"
green="\e[1;32m"
red="\e[1;31m"
dim="\e[2m"
undim="\e[0m"
# disk usage: ignore zfs, squashfs & tmpfs
mapfile -t dfs < <(df -H -x zfs -x squashfs -x tmpfs -x devtmpfs --output=target,pcent,size | tail -n+2)
printf "\ndisk usage:\n"
for line in "${dfs[@]}"; do
# get disk usage
usage=$(echo "$line" | awk '{print $2}' | sed 's/%//')
used_width=$((($usage*$bar_width)/100))
# color is green if usage < max_usage, else red
if [ "${usage}" -ge "${max_usage}" ]; then
color=$red
else
color=$green
fi
# print green/red bar until used_width
bar="[${color}"
for ((i=0; i<$used_width; i++)); do
bar+="="
done
# print dimmmed bar until end
bar+="${white}${dim}"
for ((i=$used_width; i<$bar_width; i++)); do
bar+="="
done
bar+="${undim}]"
# print usage line & bar
echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $1, $2, $3); }' | sed -e 's/^/ /'
echo -e "${bar}" | sed -e 's/^/ /'
done