Skip to content

Instantly share code, notes, and snippets.

@P4z
Created April 22, 2016 21:37
Show Gist options
  • Save P4z/a9165447e377f25a4cedf90e21e382bd to your computer and use it in GitHub Desktop.
Save P4z/a9165447e377f25a4cedf90e21e382bd to your computer and use it in GitHub Desktop.
/etc/motd.tcl
#!/usr/bin/env tclsh
# MOTD script original? / mod mewbies.com / mod P4
# http://www.mewbies.com/how_to_customize_your_console_login_message_tutorial.htm
# * Variables
set var(user) $env(USER)
set var(path) $env(PWD)
set var(home) $env(HOME)
# * Calculate current system uptime
set uptime [exec -- /usr/bin/cut -d. -f1 /proc/uptime]
set up(days) [expr {$uptime/60/60/24}]
set up(hours) [expr {$uptime/60/60%24}]
set up(mins) [expr {$uptime/60%60}]
set up(secs) [expr {$uptime%60}]
# * Calculate usage of home directory
set usage [lindex [exec -- /usr/bin/du -ms $var(home)] 0]
set usager [lindex [exec -- /bin/df / | grep dev] 4]
# * Calculate SSH logins:
set logins [exec -- users | wc -w]
set log(c) [lindex $logins 3]
# * Calculate processes
set psu [lindex [exec -- ps U $var(user) h | wc -l] 0]
set psa [lindex [exec -- ps -A h | wc -l] 0]
# * Calculate current system load
set loadavg [exec -- /bin/cat /proc/loadavg]
set sysload(1) [lindex $loadavg 0]
set sysload(5) [lindex $loadavg 1]
set sysload(15) [lindex $loadavg 2]
# * Calculate Memory
set memory [exec -- free -m]
set mem(t) [lindex $memory 7]
set mem(u) [lindex $memory 8]
set mem(f) [lindex $memory 9]
set mem(c) [lindex $memory 16]
#set mem(s) [lindex $memory 19]
# P4's stuff
set krn [exec -- uname -mrv]
if { 0 } then {
set iiid "II not running!"
set iiargs ""
} else {
set iiid [lindex [exec -- ps -u iirc --no-headers -o pid=PID,args=CMD -C ii | grep -vi screen] 0]
set iiargs [lrange [exec -- ps -u iirc --no-headers -o pid=PID,args=CMD -C ii | grep -vi screen] 1 end]
}
# colors
# set c_blue "[\033[0;34m]"
# set c_lblue "[\033[1;34m]"
# set c_red "[\033[0;31m]"
# set c_lred "[\033[1;31m]"
# set c_no "[\033[0m]"
set fortune [exec -- /usr/games/fortune -s | /usr/games/cowsay -f head-in]
puts "\033\[0;32m$fortune\033\[0m"
# * ascii head
set head {
.sSSSSs. .sSSSsSS SSsSSSSS .sSSSSs. .sSSSSs. .sSSS s.
SSSSSSSSSs. SSSSS SSS SSSSS SSSSSSSSSs. SSSSSSSSSs. SSSSS SSSs.
S SSS SSSSS S SSS S SSSSS S SSS SSSS' S SSS SSSSS S SSS SSSSS
S SS SSSSS S SS SSSSS S SS S SS SSSSS S SS SSSSS
S..SSsSSSSS S..SS SSSSS `SSSSsSSSa. S..SS SSSSS S..SSsSSSSS
S:::S SSSSS S:::S SSSSS .sSSS SSSSS S:::SsSSSSS SSSSS
S;;;S SSSSS S;;;S SSSSS S;;;S SSSSS .sSs. S;;;S SSSSS
S###S SSSSS S###S SSSSS S###S SSSSS S###S S###S SSSSS
SSSSS SSSSS SSSSS SSSSS SSSSSsSSSSS `:;:' SSSSS SSSSS}
# * Print Output
#uts "\033\[1;32m$head\033\[0m"
puts "\033\[1;32m .....................................................\033\[1;31mams.4irc.com\033\[1;32m.....\033\[0m
"
puts " \033\[1;30mUptime\033\[0m........: \033\[0;31m$up(days)\033\[0m days \033\[0;31m$up(hours)\033\[0m hours \033\[0;31m$up(mins)\033\[0m minutes \033\[0;31m$up(secs)\033\[0m seconds"
puts " \033\[1;30mLoad\033\[0m..........: \033\[0;31m$sysload(1)\033\[0m (1minute) \033\[0;31m$sysload(5)\033\[0m (5minutes) \033\[0;31m$sysload(15)\033\[0m (15minutes)"
puts " \033\[1;30mMemory\033\[0m........: \033\[0;31m$mem(t)\033\[0m MB Used: \033\[0;31m$mem(u)\033\[0m MB Free: \033\[0;31m$mem(f)\033\[0m MB Free Cached: \033\[0;31m$mem(c)\033\[0m MB"
puts " \033\[1;30mHome Usage\033\[0m....: You're using \033\[0;31m${usage}\033\[0m MB in \033\[0;31m$var(home)\033\[0m"
puts " \033\[1;30mRoot Usage\033\[0m....: Filesystem uses \033\[0;31m${usager}\033\[0m of space in \033\[0;31m/\033\[0m"
puts " \033\[1;30mSSH Logins\033\[0m....: \033\[0;31m$logins\033\[0m user(s) logged in"
puts " \033\[1;30mProcesses\033\[0m.....: \033\[0;31m$psa\033\[0m total running of which \033\[1;31m$psu\033\[0m are yours"
puts " \033\[1;30mSuckless \033\[0;31mIRC\033\[0m..: \033\[1;31m$iiid\033\[0m : \033\[0;31m$iiargs\033\[0m"
puts " \033\[1;30mKernel\033\[0m........: \033\[0;31m$krn\033\[0m"
puts " ::::::::::::::::::::::::::::::: \033\[0;31m-RULES-\033\[0m :::::::::::::::::::::::::::::::"
#puts " This is a private system that you are not to give out access to anyone"
#puts " without permission from the admin. No illegal files or activity. Stay,"
#puts " in your home directory, keep the system clean, and make regular backups."
puts " -== \033\[1;31mDISABLE YOUR PROGRAMS FROM KEEPING SENSITIVE LOGS OR HISTORY\033\[0m ==-\n"
if {[file exists /etc/news]&&[file readable /etc/news]} {
puts " . .. More or less important system news:\n"
set fp [open /etc/news]
while {-1!=[gets $fp line]} {
puts " ..) $line"
}
close $fp
puts ""
}
puts [exec -- /usr/bin/cal -B1 -A1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment