Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import os, argparse, sys, subprocess, getpass
- # Define static issued commands to remote linux instances:
- kern = 'uname -a'
- redrel = 'cat /etc/redhat-release'
- glibcv = 'rpm -qa | grep glibc'
- yums = 'yum --security check-update'
- bugz = 'yum updateinfo list bugzillas'
- homedir = os.environ['HOME']
- username = getpass.getuser()
- '''
- The following options will be imported from the files as variables passed to the python interpreter.
- client
- clientenv
- hosts ( This will be in a list format.)
- domain
- '''
- def runall():
- for filename in os.listdir('/var/environments/profile'):
- execfile(filename)
- for hosts in filename:
- call('ssh -i homedir/.ssh/id_rsa -l username hosts.clientenv.client.domain \' kern && redrel && glibcv && yums && bugz\'')
- def runenv():
- execfile('/var/environments/profile/catenv')
- for hosts in catenv:
- call('ssh -i homedir/.ssh/id_rsa -l username hosts.clientenv.client.domain \' kern && redrel && glibcv && yums && bugz\'')
- def logger():
- if outputfile is not None:
- sys.stdout = open('oname', 'w')
- if __name__ == "__main__":
- parser = argparse.ArgumentParser(description='Options for usage.')
- parser.add_argument('--all', action='store_true', help='This option applies against all files in /var/environments/profile/')
- parser.add_argument('--environment', type=str, action='store', help='This option provides an environment, like MTSOS-DEV in which to run against.')
- parser.add_argument('--output', type=str, action='store', help='This option defines an output file for this application, useful for generating a report')
- args = parser.parse_args()
- catall = print(args.all)
- ename = print(args.environment)
- oname = print(args.output)
- if catall is not None:
- catenv = '1'
- if oname is not None:
- outputfile = oname
- if ename is not None and catall is None:
- catenv = ename
- elif ename is None and catall is None:
- sys.exit('Error in options, all option cannot be set with a specific env option, nothing to do, exiting...')
- # Logical operations
- if catenv == '1':
- logger()
- runall()
- elif catenv != 1:
- logger()
- runenv()
- else:
- sys.exit('No logical condition currently applies to targets, exiting...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement