Alex Whatley's picture

Hey,

 

I have recently installed Turnkey Domain controller to run in my network. I would like to set up the MOTD on ssh login to show more then just the free space on "/". I cannot figure out how to change it. I have tried adding a line to the file /usr/bin/turnkey-sysinfo but it will only replace the disk usage and not add another one to it.

 

Any help would be great.

 

Alex

Forum: 
Jeremy Davis's picture

But Debian has a wiki page on it (TKL v12.x is based on Debian 6/Squeeze).

Alex Whatley's picture

Hey,

 

Its the turnkey-sysinfo that i am having issues, the MOTD pulls info from that file, and I cannot seem to figure it out.

 

 

#!/usr/bin/python
# Copyright (c) 2010 Liraz Siri <liraz@turnkeylinux.org>
# This file is part of turnkey-sysinfo
# turnkey-sysinfo is open source software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
import os
import re
 
import disk
from memstats import MemoryStats
 
from datetime import datetime
import netinfo 
 
import commands
 
NIC_BLACKLIST = ('lo')
 
def get_nics():
    nics = []
 
    for ifname in netinfo.get_ifnames():
        if ifname in NIC_BLACKLIST:
            continue
 
        nic = netinfo.InterfaceInfo(ifname)
        if nic.is_up and nic.address:
            nics.append((ifname, nic.address))
 
    nics.sort(lambda a,b: cmp(a[0], b[0]))
    return nics
 
def get_loadavg():
    return os.getloadavg()[0]
 
def get_pids():
    return [ int(dentry) for dentry in os.listdir("/proc") 
             if re.match(r'\d+$', dentry) ]
 
def main():
    system_load = "System load:  %.2f" % get_loadavg()
 
    processes = "Processes:    %d" % len(get_pids())
    disk_usage = "Usage of /:   "  + disk.usage("/") 
   When I try to add another line of disk_usage it just overwrites the current one     
 
    memstats = MemoryStats()
 
    memory_usage = "Memory usage:  %d%%" % memstats.used_memory_percentage
    swap_usage = "Swap usage:    %d%%" % memstats.used_swap_percentage
 
    rows = []
    rows.append((system_load, memory_usage))
    rows.append((processes, swap_usage))
   
    nics = [ "IP address for %s:  %s" % (nic, address)
             for nic, address in get_nics() ]
 
    column = [disk_usage]
    if nics:
        column.append(nics[0])
    rows.append(column)
    for nic in nics[1:]:
        rows.append(('', nic))
 
    print "System information (as of %s)" % datetime.now().strftime("%a %b %d %H:%M:%S %Y")
    print
    max_col = max([ len(row[0]) for row in rows ])
    tpl = "  %%-%ds   %%s" % max_col
    for row in rows:
        print tpl % (row[0], row[1])
 
    if os.geteuid() == 0:
        error, output = commands.getstatusoutput("tklbam-status")
        error_nosuchcommand = (os.WEXITSTATUS(error) == 127)
 
        if not error_nosuchcommand:
            print
            print output,
 
if __name__=="__main__":
    main()
 
I have written in bold what i have tried, I hope this might help a little more.
 
Thanks,
 
Alex
Jeff Pitoniak's picture

Ok so I added a separate data volume to separate file shares from system volume, and I also wanted to know disk space of the volume supporting the file shares on login.

Here's what my current MOTD looks like:

Linux smbserver 2.6.32-45-generic-pae #102-Ubuntu SMP Wed Jan 2 22:10:16 UTC 2013 i686 GNU/Linux
Ubuntu 10.04.2 LTS
Welcome to Smbserver, TurnKey Linux 11.1 / Ubuntu 10.04 Lucid LTS

  System information (as of Wed Apr 03 05:21:18 2013)

    System load:  0.00                     Memory usage:  32%
    Processes:    111                      Swap usage:    2%
    Usage of /:   45.1% of 16.73GB         IP address for eth0:  192.168.x.x
    Usage of /data/:   95.0% of 125.89GB

  TKLBAM (Backup and Migration):  NO BACKUPS

    To backup for the first time run the "tklbam-backup" command. For
    details see the man page or go to:

        http://www.turnkeylinux.org/tklbam

Last login: Tue Apr  2 17:25:12 2013 from xxxxxx

 

I edited the file with vi /usr/lib/turnkey-sysinfo/turnkey-sysinfo.py

Use pico if vi confuses you.

Under def_main(): I added a new disk.usage variable (disk_usage1) right after the first one referencing where I mounted the second disk,

disk_usage = "Usage of /: " + disk.usage("/")
disk_usage1 = "Usage of /data/: " + disk.usage("/srv/storage/data")

 

then added a "row" with rows.append((disk_usage1,'')) in front of the print statements which pull everything together. 

    for nic in nics[1:]:
        rows.append(('', nic))
    rows.append((disk_usage1,'')) 

 

 Hope this helps.

 

Best regards,

Jeff

--


 

Add new comment