add rc file
This commit is contained in:
29
nando
29
nando
@@ -1,21 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import socket,sys,time,os
|
import socket,sys,time,os,configobj
|
||||||
|
|
||||||
|
RC="/etc/nandorc"
|
||||||
|
|
||||||
def setup_options():
|
def setup_options():
|
||||||
''' Setup the command line options '''
|
''' Setup the command line options '''
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
parser=ArgumentParser(description="Alive notifier.")
|
parser=ArgumentParser(description="Alive notifier. Options first read from /etc/nandorc, and overriden by switches.")
|
||||||
parser.add_argument("--host",action='store', dest='HOST',type=str,required=True,
|
parser.add_argument("--host",action='store', dest='HOST',type=str,default=None,
|
||||||
help="Host name/IP of the server")
|
help="Host name/IP of the server")
|
||||||
parser.add_argument("--port", action='store', dest='PORT', default=13370,type=int,
|
parser.add_argument("--port", action='store', dest='PORT', default=None,type=int,
|
||||||
help="Port number of the server")
|
help="Port number of the server")
|
||||||
parser.add_argument("-t",action='store', dest='TIMEOUT',default=5, type=int,
|
parser.add_argument("-t",action='store', dest='TIMEOUT',default=5, type=int,
|
||||||
help="Connection timeout")
|
help="Connection timeout")
|
||||||
parser.add_argument("-i",action='store', dest='INTERVAL',default=0, type=int,
|
parser.add_argument("-i",action='store', dest='INTERVAL',default=0, type=int,
|
||||||
help="Send signal every i seconds. If 0, send only once and exit.")
|
help="Send signal every i seconds. If 0, send only once and exit.")
|
||||||
parser.add_argument("-m",action='store', dest='MSGFILE',type=str,default=False,
|
parser.add_argument("-m",action='store', dest='MSGFILE',type=str,default=None,
|
||||||
help="Read a text file as description. Max length 512 chars")
|
help="Read a text file as description. Max length 512 chars")
|
||||||
parser.add_argument("--query-ip",action='store', dest='QUERY_HOSTNAME',default=None,type=str,
|
parser.add_argument("--query-ip",action='store', dest='QUERY_HOSTNAME',default=None,type=str,
|
||||||
help="Query the IP of a host name")
|
help="Query the IP of a host name")
|
||||||
@@ -25,8 +27,25 @@ def setup_options():
|
|||||||
choices=['','list','alive','lost'],
|
choices=['','list','alive','lost'],
|
||||||
help="Command to send. If empty, send standard alive-notice. Commands: list, alive")
|
help="Command to send. If empty, send standard alive-notice. Commands: list, alive")
|
||||||
options=parser.parse_args()
|
options=parser.parse_args()
|
||||||
|
if os.path.exists(RC):
|
||||||
|
rc=configobj.ConfigObj(RC)
|
||||||
|
if options.HOST is None:
|
||||||
|
if "HOST" in rc.keys():
|
||||||
|
options.HOST=rc['HOST']
|
||||||
|
if options.PORT is None:
|
||||||
|
if "PORT" in rc.keys():
|
||||||
|
options.PORT=int(rc['PORT'])
|
||||||
|
if options.MSGFILE is None:
|
||||||
|
if "MSGFILE" in rc.keys():
|
||||||
|
options.MSGFILE=rc['MSGFILE']
|
||||||
|
|
||||||
|
if options.HOST is None:
|
||||||
|
parser.error("Host name required")
|
||||||
|
if options.PORT is None:
|
||||||
|
parser.error("Port number required")
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
def print_table(data):
|
def print_table(data):
|
||||||
lengths=[0,0,0,0]
|
lengths=[0,0,0,0]
|
||||||
for row in data.split("\n"):
|
for row in data.split("\n"):
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ function filesize {
|
|||||||
}' || return $?
|
}' || return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Gather list of last user of machine
|
# Gather list of last user of machine
|
||||||
|
|
||||||
LASTUSER=$( who | tail -n 1 | awk '{ print $1 }' )
|
LASTUSER=$( who | tail -n 1 | awk '{ print $1 }' )
|
||||||
|
|||||||
Reference in New Issue
Block a user