autocheck_day.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Dec 3 23:30:49 2018
  5. @author: dufs
  6. """
  7. import logging.config
  8. import hostinfo as hf
  9. import sshclient as sshcl
  10. if __name__ == '__main__':
  11. logging.config.fileConfig("conf/logging.conf")
  12. #create logger
  13. logger = logging.getLogger("autocheck")
  14. hostList=hf.get_hostinfo()
  15. if hostList[0]!=0:
  16. logger.error('get hostinfo error')
  17. raise
  18. hostSet=set()
  19. for host in hostList[1]:
  20. if host[3] is None or len(host[3])==0 or host[4] is None or len(host[4])==0:
  21. continue
  22. hostSet.add((host[1], int(host[2]), host[3], host[4], host[0]))
  23. logger.info('get host number %d', len(hostSet))
  24. if len(hostSet)>0:
  25. cmdSet=set()
  26. cmdSet.add(('userinfo', '''cat /etc/passwd |awk -F":" '{print $1}' '''))
  27. cmdSet.add(('mkmfsinfo', "sudo -u root mkmfsinfo -querydisk |awk '{print $1,$8}'"))
  28. sshcl.ssh_batch_cmd(hostSet, cmdSet)
  29. logger.info('exec autocheck_day finished')