From de3b90af34cb4b18d7d76dd0f5a3ba99df19114b Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Mon, 13 Jul 2015 12:07:58 +0300 Subject: [PATCH] add rc file --- nando | 29 ++++++++++++++++++++++++----- nando-desc | 1 - 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/nando b/nando index a906369..6989018 100755 --- a/nando +++ b/nando @@ -1,21 +1,23 @@ #!/usr/bin/env python -import socket,sys,time,os +import socket,sys,time,os,configobj + +RC="/etc/nandorc" def setup_options(): ''' Setup the command line options ''' from argparse import ArgumentParser - parser=ArgumentParser(description="Alive notifier.") - parser.add_argument("--host",action='store', dest='HOST',type=str,required=True, + 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,default=None, 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") parser.add_argument("-t",action='store', dest='TIMEOUT',default=5, type=int, help="Connection timeout") 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.") - 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") parser.add_argument("--query-ip",action='store', dest='QUERY_HOSTNAME',default=None,type=str, help="Query the IP of a host name") @@ -25,8 +27,25 @@ def setup_options(): choices=['','list','alive','lost'], help="Command to send. If empty, send standard alive-notice. Commands: list, alive") 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 + def print_table(data): lengths=[0,0,0,0] for row in data.split("\n"): diff --git a/nando-desc b/nando-desc index abbdc81..3967b0e 100755 --- a/nando-desc +++ b/nando-desc @@ -23,7 +23,6 @@ function filesize { }' || return $? } - # Gather list of last user of machine LASTUSER=$( who | tail -n 1 | awk '{ print $1 }' )