Skip to content

Instantly share code, notes, and snippets.

@mszynka
Created March 30, 2016 18:57
Show Gist options
  • Save mszynka/1c55fdd7f94bc51a66f0ac9e17590c7b to your computer and use it in GitHub Desktop.
Save mszynka/1c55fdd7f94bc51a66f0ac9e17590c7b to your computer and use it in GitHub Desktop.
Custom login message (motd) script

#Custom login message

Example

Last login: Wed Oct 22 21:12:10 2015 from *****
  ___  ___ _____                     _  
  |  \/  |/  ___|                   | | 
  | .  . |\ `--.  ____ _   _  _ __  | | __  __ _ 
  | |\/| | `--. \|_  /| | | || `_ \ | |/ / / _` |
  | |  | |/\__/ / / / | |_| || | | ||   < | (_| |
  \_|  |_/\____/ /___| \__, ||_| |_||_|\_\ \__,_|
                        __/ | 
                       |___/  


  Last Logins...: ******  pts/0        ******    Date... 21:21   still logged in
                  ******  pts/0        ******    Date... 21:12 - 21:12  (00:00)
                  ******  pts/0        ******    Date... 21:12 - 21:12  (00:00)
                  ******  pts/0        ******    Date... 21:01 - 21:12  (00:10)
                  -----------------------
                  now user1
  Uptime........: up 3 hours, 3 minutes
  Load..........: 0.00 0.01 0.05
  Memory MB.....: 29/876MB (3.31%)
  Disk Usage....: 1.5/20GB (8%)
  Temperature...: 65.0 degrees C
  SSH Logins....: There are currently 1 users logged in
  Processes.....: 72 total running of which 5 is yours


  ::::::::::::::::::::::::::::::::::-RULES-::::::::::::::::::::::::::::::::::
    This is a private system that you are not to give out access to anyone
    without permission from the admin. No illegal files or activity. Stay,
    in your home directory, keep the system clean, and make regular backups.
     -==  DISABLE YOUR PROGRAMS FROM KEEPING SENSITIVE LOGS OR HISTORY ==-


   _______________________________________
  / You don`t know who I am and frankly   \
  | shouldn`t care, but unknown to you we |
  | have something in common. We are both |
  \ rather prone to mistakes.             /
   --------------------------------------- 
          \   ,__,
           \  (oo)____
              (__)    )\
                 ||--|| *

Usage

  1. Put motd.sh somewhere accesible (preferably '/etc/')
  2. echo 'sh /etc/motd.sh/' >> ~/{.bashrc, .zshrc}

Credits

I have never been good at writing readme's so if You think I owe You something just leave a message.

#!/bin/bash
# * Variables
user=$(whoami)
path=$(pwd)
home=$HOME
# * Calculate last login
lastlog1=$(last -i -d -n 1 -w | head -1)
lastlog2=$(last -i -d -n 2 -w | head -2 | tail -1)
lastlog3=$(last -i -d -n 3 -w | head -3 | tail -1)
lastlog4=$(last -i -d -n 4 -w | head -4 |tail -1)
logincount=$( users | wc -w)
# * Calculate current system uptime
uptime=$(uptime -p)
# * Calculate memory
memory=$(free -m | awk 'NR==2{printf "%d/%sMB (%.2f%)", $3,$2,$3*100/$2 }')
# * Calculate usage
usage=$(df -h | grep " /$" | cut -f4 | awk '{printf "%3.1f/%sB (%s)", $3, $2, $5}')
# * Calculate SSH logins:
logins=$(users)
# * Calculate processes
psa=$(expr $(ps -A h | wc -l) - 2)
psu=$(expr $(ps U $user h | wc -l) - 2)
# * Calculate current system load
sysload1=$(cat /proc/loadavg | cut -d' ' -f1)
sysload2=$(cat /proc/loadavg | cut -d' ' -f2)
sysload3=$(cat /proc/loadavg | cut -d' ' -f3)
# * Calculate temperature from lm-sensors
temp=$(acpi -t | cut -d',' -f2)
# * ASCII head
echo ' ___ ___ _____ _ '
echo ' | \/ |/ ___| | | '
echo ' | . . |\ `--. ____ _ _ _ __ | | __ __ _ '
echo ' | |\/| | `--. \|_ /| | | || `_ \ | |/ / / _` |'
echo ' | | | |/\__/ / / / | |_| || | | || < | (_| |'
echo ' \_| |_/\____/ /___| \__, ||_| |_||_|\_\ \__,_|'
echo ' __/ | '
echo ' |___/ '
echo $'\n'
# * Print Output
echo " Last Logins...: $lastlog1"
echo " $lastlog2"
echo " $lastlog3"
echo " $lastlog4"
echo " -----------------------"
echo " now $logins"
echo " Uptime........: $uptime"
echo " Load..........: $sysload1 $sysload2 $sysload3"
echo " Memory MB.....: $memory"
echo " Disk Usage....: $usage"
echo " Temperature...:$temp"
echo " SSH Logins....: There are currently $logincount users logged in"
echo " Processes.....: $psa total running of which $psu is yours"
echo $'\n'
echo " ::::::::::::::::::::::::::::::::::-RULES-::::::::::::::::::::::::::::::::::"
echo " This is a private system that you are not to give out access to anyone"
echo " without permission from the admin. No illegal files or activity. Stay,"
echo " in your home directory, keep the system clean, and make regular backups."
echo " -== DISABLE YOUR PROGRAMS FROM KEEPING SENSITIVE LOGS OR HISTORY ==-"
echo $'\n'
echo " _______________________________________"
echo " / You don't know who I am and frankly \\"
echo " | shouldn't care, but unknown to you we |"
echo " | have something in common. We are both |"
echo " \ rather prone to mistakes. /"
echo " --------------------------------------- "
echo " \ ,__,"
echo " \ (oo)____"
echo " (__) )\\"
echo " ||--|| *"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment