MOTD

Автор: | 2016-12-08

Как приукрасить процесс логина.

В файлик /etc/profile  добавляем в конец новую строчку.

1 [ “$PS1” ] && /usr/local/sbin/MOTD.py

Кладем по пути собственно MOTD.py не забывая дать ему права на исполнение (755).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 #!/usr/bin/env python

# -*- coding: utf-8 -*- #
#  fpbxmotd.py
#
#  Copyright 2012 James Finstrom <jfinstrom at gmail.com>
#
#  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.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#
import socket
import os
import sys
import fcntl
import struct
import subprocess
banner=””” *         * * host id * *         *                           “””
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” % banner )     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()

Теперь при логине видим полезную актуальную информацию. Наслаждаемся.