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