Подсмотрел у FreePBX Как приукрасить процесс логина.
В файлик /etc/profile добавляем в конец новую строчку.
[ “$PS1” ] &&& /usr/local/sbin/MOTD.py
Кладем по пути собственно MOTD.py не забывая дать ему права на исполнение (755).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# fpbxmotd.py
#
# Copyright 2012 James Finstrom
#
# This program is free 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 2 of the License, or
# (at your option) any later version.
#
#
# ADD to /etc/profile
#
# [ "$PS1" ] && /usr/local/sbin/MOTD.py
#
import socket
import os
import sys
import fcntl
import struct
import subprocess
banner=""
def getIpAddr(ifname):
""" getIpAddr(networkInterface)
By: Bryce Chidester
Gets the IPv4 address of the provided network interface ie: eth0
"""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except Exception, e:
sys.stderr.write( "Unable to open UNIX system socket: %s\n" % e )
return ""
try:
info = fcntl.ioctl(sock.fileno(), 0x8915, struct.pack('256s', ifname[:15]))
except IOError, e:
# Usually this is "Does not exist"
#sys.stderr.write( "Exception while fetching interface information for %s: %s\n" % (ifname, e) )
(errno, errstr) = e
sock.close()
return "%s" % ('No IP')
#return "Unable to fetch information for %s: %s" % (ifname, errstr)
sock.close()
return socket.inet_ntoa(info[20:24])
def getMacAddr(ifname):
""" getMacAddr(networkInterface)
By: Bryce Chidester
Gets the Mac address of the provided network interface ie: eth0
"""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except Exception, e:
sys.stderr.write( "Unable to open UNIX system socket: %s\n" % e )
return ""
try:
info = fcntl.ioctl(sock.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
except IOError, e:
# Usually this is "Does not exist"
sys.stderr.write( "Exception while fetching interface information for %s: %s\n" % (ifname, e) )
(errno, errstr) = e
sock.close()
return "%s: %s" % (ifname, errstr)
#return "Unable to fetch information for %s: %s" % (ifname, errstr)
sock.close()
hwaddr = []
for char in info[18:24]:
hwaddr.append("%02X" % ord(char))
return ':'.join(hwaddr)
def main():
ifdata = ''
iflist = os.listdir('/sys/class/net/')
for i in iflist:
if i == 'lo':
#Skip loopback
continue
ifdata += "Interface %s IP: %s\n" % (i,getIpAddr(i))
ifdata += "Interface %s MAC: %s\n" % (i,getMacAddr(i))
sys.stdout.write( "%s\n" % ifdata )
sys.stdout.write( "Screen session list: \n\n")
p = subprocess.Popen("screen -list | grep -s -i -E \"Detached|Attached\"", shell=True, stdout=subprocess.PIPE)
scrlist = p.stdout.read()
# scrlist = scrlist.lstrip()
if scrlist== '':
sys.stdout.write( "No active session \n")
else:
result = scrlist.split()
sesnum = len(result) # lendth of list (spisok)
# sys.stdout.write( "%s \n" % (sesnum))
i = 0
while i < sesnum:
iz = i +1
sys.stdout.write( "screen -R %s on %s state:%s \n" % (result[i].split(".")[0] , result[i].split(".")[1], result[iz]))
# sys.stdout.write( "screen -R %s \n" % (result[2].split(".")[0]))
i = i + 2
sys.stdout.write( "\nUse \" screen -list \" to view this lst any time \n")
return 0
if __name__ == '__main__':
main()
Теперь при логине видим полезную актуальную информацию. Наслаждаемся.
<>Август 2013 >