Advertisement
bt90

Raspberry Pi: MOTD (SSH Greeting)

Feb 8th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.63 KB | None | 0 0
  1. #! /bin/bash
  2. ##############################################
  3. #          Created by Thomas Butz            #
  4. #   E-Mail: btom1990(at)googlemail(dot)com   #
  5. #   Feel free to copy & share this script    #
  6. ##############################################
  7.  
  8.  
  9. ################### HOWTO ####################
  10. # 1. Save this script as /usr/local/bin/motd
  11. # 2. sudo chmod +x /usr/local/bin/motd
  12. # 3. Edit /etc/profile to call the script in the last line(simply type: motd)
  13. # 4. sudo echo '' > /etc/motd
  14. # 5. sudo echo '' > /etc/motd.tail
  15. # 6. sudo echo '' > /var/run/motd.dynamic
  16. # 7. sudo sed -i "/.*uname/s/^/#/g" /etc/init.d/motd
  17. # 8. Reconnect and admire your shiny new SSH greeting!
  18. ##############################################
  19.  
  20. # Hostname
  21. host=$(uname -n)
  22.  
  23. # Kernel
  24. kernel=$(uname -r)
  25.  
  26. # Public IP
  27. ip=$(curl -sm 3 http://icanhazip.com)
  28.  
  29. # Uptime
  30. up[0]=$(cat /proc/uptime | cut -d. -f1)
  31. let up[1]=${up[0]}/60/60/24 # days
  32. let up[2]=${up[0]}/60/60%24 # hours
  33. let up[3]=${up[0]}/60%60    # minutes
  34. let up[4]=${up[0]}%60       # seconds
  35.  
  36. # Sysload
  37. load=($(cat /proc/loadavg))
  38.  
  39. # Memory
  40. mem[0]=$(free -mo | tr -dc '[:digit:][:blank:]' | tr -s ' ')
  41. mem[1]=$(echo ${mem[0]} | cut -d' ' -f1) # total
  42. mem[2]=$(echo ${mem[0]} | cut -d' ' -f2) # used
  43. mem[3]=$(echo ${mem[0]} | cut -d' ' -f8) # used Swap
  44.  
  45. # Temperature
  46. temp=$(vcgencmd measure_temp | tr -dc '[:digit:].')
  47.  
  48. # Disk Usage
  49. usage=$(df / | tail -n 1 |tr -s ' ' | cut -d' ' -f5) # Root filesystem
  50.  
  51. # Logins
  52. let log=$(w -s | wc -l)-2
  53.  
  54. # Processes
  55. psu=$(ps U $USER h | wc -l)
  56. psa=$(ps -A h | wc -l)
  57.  
  58. # Text colors
  59. blk='\e[0;30m' # black
  60. red='\e[0;31m' # red
  61. grn='\e[0;32m' # green
  62. nc='\e[0m'     # no color
  63.  
  64. # Print info
  65. echo
  66. echo -e "${grn}     .~~.   .~~.     ${red}Hostname...:${grn} $host${nc}"
  67. echo -e "${grn}    '. \ ' ' / .'    ${red}Kernel.....:${grn} $kernel${nc}"
  68. echo -e "${grn}     .~ .~~~..~.     ${red}Public IP..:${grn} $ip${nc}"
  69. echo -e "${red}    : .~.'~'.~. :    ${red}Uptime.....:${grn} ${up[1]} days, ${up[2]} hours, ${up[3]} minutes, ${up[4]} seconds${nc}"
  70. echo -e "${red}   ~ (   ) (   ) ~   ${red}Load.......:${grn} ${load[0]} (1min) ${load[1]} (5min) ${load[2]} (15min)${nc}"
  71. echo -e "${red}  ( : '~'.~.'~' : )  ${red}Memory ....:${grn} Total: ${mem[1]} MB, Used: ${mem[2]} MB, Swap: ${mem[3]} MB${nc}"
  72. echo -e "${red}   ~ .~ (   ) ~. ~   ${red}Temperature:${grn} $temp°C${nc}"
  73. echo -e "${red}    (  : '~' :  )    ${red}Disk Usage.:${grn} ${usage}${nc}"
  74. echo -e "${red}     '~ .~~~. ~'     ${red}Logins.....:${grn} There are currently $log users logged in${nc}"
  75. echo -e "${red}         '~'         ${red}Processes..:${grn} Total: $psa, User: $psu${nc}"
  76. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement