Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > OS X > Mac OS X Server, Xserve, and Networking

Thread Tools Search this Thread Display Modes
Old Feb 9, 2014, 07:34 PM   #1
macrumors 6502
Join Date: Feb 2014
**Dynamic** MOTD?

I posted about this before, but I wasn't too clear in the post or the post title.

What I need to know is how to set dynamic variables in a MOTD:

Has anyone a MPTD that shows dynamoc system information, such as the home path of the user, free ram, available disc space (for the user), last login, and so forth?

(It would also be useful is someone could give an example of proper colour code usage in a dynamic script on OSX, although I can do that myself.)

For example, what would be the OSX equivalent of this:

load=`cat /proc/loadavg | awk '{print $1}'`
root_usage=`df -h / | awk '/\// {print $(NF-1)}'`
memory_usage=`free -m | awk '/Mem/ { printf("%3.1f%%", $3/$2*100) }'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
users=`users | wc -w`

echo "System information as of: $date"
printf "System load:\t%s\tMemory usage:\t%s\n" $load $memory_usage
printf "Usage on /:\t%s\tSwap usage:\t%s\n" $root_usage $swap_usage
printf "Local users:\t%s\n" $users

...or this....

# * Calculate last login
set lastlog [exec -- lastlog -u $var(user)]
set ll(1) [lindex $lastlog 7]
set ll(2) [lindex $lastlog 8]
set ll(3) [lindex $lastlog 9]
set ll(4) [lindex $lastlog 10]
set ll(5) [lindex $lastlog 6]

# * 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]

# * Calculate SSH logins:
set logins [exec -- w -s]
set log(c) [lindex $logins 5]

# * 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]

puts " Last Login....: $ll(1) $ll(2) $ll(3) $ll(4) from $ll(5)"
puts " Uptime........: $up(days)days $up(hours)hours $up(mins)minutes $up(secs)seconds"
puts " Load..........: $sysload(1) (1minute) $sysload(5) (5minutes) $sysload(15) (15minutes)"
puts " Memory MB.....: $mem(t) Used: $mem(u) Free: $mem(f) Free Cached: $mem(c) Swap In Use: $mem(s)"
puts " Disk Usage....: You're using ${usage}MB in $var(home)"
puts " SSH Logins....: There are currently $log(c) users logged in."

Running OSX Server 10.5.8.

Last edited by AmestrisXServe; Feb 9, 2014 at 08:55 PM.
AmestrisXServe is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > OS X > Mac OS X Server, Xserve, and Networking

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Anyone want more dynamic wallpapers? Russiaone iOS 7 13 Feb 24, 2014 12:08 PM
Dynamic Wallpaper thegrants82 iOS 7 3 Jan 22, 2014 02:38 PM
Dynamic wallpaper TyWahn iOS 7 0 Oct 31, 2013 12:32 AM
Dynamic Wallpapers bluespider iOS 7 1 Sep 12, 2013 04:52 PM
Dynamic Wallpapers acctman iOS 7 4 Jun 11, 2013 01:15 PM

Forum Jump

All times are GMT -5. The time now is 01:22 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC