#!/usr/bin/env python """ Connection to download server updates.software-univention.de gets stuck / stalls """ import os from subprocess import Popen, PIPE SERVER = 'download2.software-univention.de' def _cmd(func, *cmd): print '# %s' % (' '.join(cmd),) proc = Popen(cmd, stdout=PIPE) for line in proc.stdout: line = line.rstrip() line = func(line) if line: print line def cmd(*cmd): _cmd(lambda l: l, *cmd) print def date(): cmd('date', '--rfc-3339=date') def ifstat(): for iface in os.listdir('/sys/class/net'): cmd('ip', '-s', 'link', 'show', iface) def netstat(): f = lambda line: line if SERVER in line else None _cmd(f, 'netstat', '-tp') def route(): f = lambda line: cmd('ip', 'route', 'get', line) or line _cmd(f, 'dig', '+short', SERVER) def lsof(): pids = set() def f(line): if SERVER in line: command, pid, user, fd, typ, device, size_off, node, name = line.split(None, 8) pids.add(pid) return line _cmd(f, 'lsof') return pids def proc(pids): if pids: cmd('ps', 'afwwwu', *list(pids)) def strace(pids): for pid in pids: cmd('timeout', '1s', 'strace', '-q', '-p', pid) def ucr(): f = lambda line: None if 'password' in line else line _cmd(f, 'ucr', 'search', '--brief', '--non-empty', '^repository/') def bugzilla(): try: import sys sys.path.insert(0, "/home/phahn/src") from bugzilla import BugzillaJson as Bugzilla except ImportError: return bug = Bugzilla() bug.get(36044) def main(): os.environ['LC_ALL'] = 'C' bugzilla() date() ifstat() netstat() route() pids = lsof() proc(pids) strace(pids) ucr() if __name__ == '__main__': main()