Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import os, argparse, sys, subprocess, getpass
  4.  
  5.  
  6.  
  7. # Define static issued commands to remote linux instances:
  8.  
  9. kern = 'uname -a'
  10. redrel = 'cat /etc/redhat-release'
  11. glibcv = 'rpm -qa | grep glibc'
  12. yums = 'yum --security check-update'
  13. bugz = 'yum updateinfo list bugzillas'
  14. homedir = os.environ['HOME']
  15. username = getpass.getuser()
  16.  
  17. '''
  18. The following options will be imported from the files as variables passed to the python interpreter.
  19. client
  20. clientenv
  21. hosts ( This will be in a list format.)
  22. domain
  23. '''
  24.  
  25. def runall():
  26. for filename in os.listdir('/var/environments/profile'):
  27. execfile(filename)
  28. for hosts in filename:
  29. call('ssh -i homedir/.ssh/id_rsa -l username hosts.clientenv.client.domain \' kern && redrel && glibcv && yums && bugz\'')
  30.  
  31.  
  32. def runenv():
  33. execfile('/var/environments/profile/catenv')
  34. for hosts in catenv:
  35. call('ssh -i homedir/.ssh/id_rsa -l username hosts.clientenv.client.domain \' kern && redrel && glibcv && yums && bugz\'')
  36.  
  37. def logger():
  38. if outputfile is not None:
  39. sys.stdout = open('oname', 'w')
  40.  
  41.  
  42. if __name__ == "__main__":
  43.  
  44. parser = argparse.ArgumentParser(description='Options for usage.')
  45. parser.add_argument('--all', action='store_true', help='This option applies against all files in /var/environments/profile/')
  46. parser.add_argument('--environment', type=str, action='store', help='This option provides an environment, like MTSOS-DEV in which to run against.')
  47. parser.add_argument('--output', type=str, action='store', help='This option defines an output file for this application, useful for generating a report')
  48. args = parser.parse_args()
  49.  
  50. catall = print(args.all)
  51. ename = print(args.environment)
  52. oname = print(args.output)
  53.  
  54. if catall is not None:
  55. catenv = '1'
  56. if oname is not None:
  57. outputfile = oname
  58. if ename is not None and catall is None:
  59. catenv = ename
  60. elif ename is None and catall is None:
  61. sys.exit('Error in options, all option cannot be set with a specific env option, nothing to do, exiting...')
  62.  
  63. # Logical operations
  64.  
  65. if catenv == '1':
  66. logger()
  67. runall()
  68. elif catenv != 1:
  69. logger()
  70. runenv()
  71. else:
  72. sys.exit('No logical condition currently applies to targets, exiting...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement