Added fallback if users array isn't set. Set timeout.
This commit is contained in:
@@ -12,4 +12,4 @@ keys:
|
||||
key: ssh-rsa XXXXXXXXX
|
||||
- name: janedoe@gmail.com
|
||||
description: Jane Doe
|
||||
key: ssh-rsa YYYYYYYYY
|
||||
key: ssh-rsa YYYYYYYYY
|
||||
|
||||
@@ -49,7 +49,7 @@ def update_keys(host, user, keys, host_length):
|
||||
try:
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
||||
client.connect(host, username = user)
|
||||
client.connect(host, username = user, timeout = 1)
|
||||
|
||||
stdin, stdout, stderr = client.exec_command('top -bn1 | grep "^top\\|^%Cpu\\|^.iB Mem"')
|
||||
stdin.close()
|
||||
@@ -70,6 +70,8 @@ def main():
|
||||
|
||||
host_length = 0
|
||||
for host in config['hosts']:
|
||||
if host.get('users') == None:
|
||||
host['users'] = ['root']
|
||||
for user in host['users']:
|
||||
if len(user) + len(host['host']) > host_length:
|
||||
host_length = len(user) + len(host['host'])
|
||||
@@ -81,6 +83,8 @@ def main():
|
||||
print('Host'.center(host_length + 3) + ' ' + 'Load'.center(25) + ' ' + 'Ram Usage'.center(26))
|
||||
|
||||
for host in config['hosts']:
|
||||
if host.get('users') == None:
|
||||
host['users'] = ['root']
|
||||
for user in host['users']:
|
||||
try:
|
||||
thread = task_thread(host['host'], user, keys, host_length)
|
||||
@@ -89,4 +93,4 @@ def main():
|
||||
print('❌ ' + user + '@' + host['host'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
6
sync.py
6
sync.py
@@ -21,7 +21,7 @@ def update_keys(host, user, keys):
|
||||
try:
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
||||
client.connect(host, username = user)
|
||||
client.connect(host, username = user, timeout = 1)
|
||||
client.exec_command('echo "###\n# Warning this file has been generated and will be overwritten!\n###\n\n' + '\n'.join(keys) + '" > ~/.ssh/authorized_keys2')
|
||||
client.close()
|
||||
print('✅ ' + user + '@' + host)
|
||||
@@ -37,6 +37,8 @@ def main():
|
||||
keys.append(key['key'])
|
||||
|
||||
for host in config['hosts']:
|
||||
if host.get('users') == None:
|
||||
host['users'] = ['root']
|
||||
for user in host['users']:
|
||||
try:
|
||||
thread = task_thread(host['host'], user, keys)
|
||||
@@ -45,4 +47,4 @@ def main():
|
||||
print('❌ ' + user + '@' + host['host'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user