Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import os, re
- def finddirs():
- r = re.compile("^ssh-[0-9A-z]+$")
- return [ ("/tmp/"+p) for p in os.listdir("/tmp") if r.match(p) ]
- def dir2path(dir):
- r = re.compile("^agent.[0-9]+$")
- return [ (dir+"/"+f) for f in os.listdir(dir) if r.match(f) ][0]
- def keyread(path):
- os.environ["SSH_AUTH_SOCK"] = path
- std = os.popen("ssh-add -l 2> /dev/null")
- raw = std.read() # socket is available
- std.close()
- print path, [raw]
- return
- def main():
- dirs = finddirs()
- # print dirs
- paths = [ dir2path(dir) for dir in dirs ]
- # print paths
- [ keyread(path) for path in paths ]
- return
- if __name__ == "__main__": main()
- # will generate
- """
- /tmp/ssh-rkxTkt5126/agent.5126 ['The agent has no identities.\n']
- /tmp/ssh-XWZBL24682/agent.24682 ['2048 * hoge_rsa (RSA)\n']
- /tmp/ssh-CEOck24254/agent.24254 ['2048 * fuga_rsa (RSA)\n']
- /tmp/ssh-Hioqcny495/agent.495 ['The agent has no identities.\n']
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement