comparison newkey.py @ 41:900ff99ec749

less noisy if success
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 03 Jan 2022 19:26:11 +0000
parents f13017bb4502
children 59517f60826d
comparison
equal deleted inserted replaced
40:f13017bb4502 41:900ff99ec749
10 2) Using ssh-copy-id via intermediary (defaults to $DESKTOP) 10 2) Using ssh-copy-id via intermediary (defaults to $DESKTOP)
11 [change this to maritain once it's worked for everbody''' # ' 11 [change this to maritain once it's worked for everbody''' # '
12 12
13 import sys, os 13 import sys, os
14 from socket import gethostname 14 from socket import gethostname
15 from subprocess import run 15 from subprocess import run, PIPE
16 16
17 hack=os.environ.copy() 17 hack=os.environ.copy()
18 hack['SSH_AUTH_SOCK']='/home/ht/.gnupg/S.gpg-agent.ssh' 18 hack['SSH_AUTH_SOCK']='/home/ht/.gnupg/S.gpg-agent.ssh'
19 19
20 def ssh_copy_id(keyfile,client): 20 def ssh_copy_id(keyfile,client):
21 print(["ssh-copy-id","-i",keyfile,client],'...',sep='',end='') 21 print(["ssh-copy-id","-i",keyfile,client],'...',sep='',end='')
22 res=run(["ssh-copy-id","-i",keyfile,client],env=hack).returncode 22 res=run(["ssh-copy-id","-i",keyfile,client],env=hack,text=True,
23 print('failed %s'%res if res else 'succeeded') 23 stdout=PIPE,stderr=PIPE)
24 if res.returncode:
25 print('failed %s'%res.returncode)
26 outs,errs=res.communicate()
27 print(errs)
28 else:
29 print('succeeded')
24 30
25 ihost=None 31 ihost=None
26 if sys.argv[1]=='-v': 32 if sys.argv[1]=='-v':
27 sys.argv.pop(1) 33 sys.argv.pop(1)
28 ihost=sys.argv.pop(1).lower() 34 ihost=sys.argv.pop(1).lower()