diff --git a/unifi_reboot.py b/unifi_reboot.py deleted file mode 100644 index 942bfb1..0000000 --- a/unifi_reboot.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python3 -import paramiko -import datetime -import sys - -# File with device list: "ip user password" -DEVICE_LIST = "unifi-devices.txt" -LOGFILE = "unifi-reboot.log" -#REBOOT_CMD = "/sbin/reboot" -REBOOT_CMD = "ls -al" - - -def log(message): - timestamp = datetime.datetime.now().strftime("[%Y-%m-%d %H:%M:%S]") - with open(LOGFILE, "a") as f: - f.write(f"{timestamp} {message}\n") - print(f"{timestamp} {message}") - -def reboot_device(ip, user, password): - log(f"Rebooting {ip} (user: {user})...") - try: - ssh = paramiko.SSHClient() - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(ip, username=user, password=password, timeout=10) - ssh.exec_command(REBOOT_CMD) - ssh.close() - log(f"SUCCESS: {ip} reboot command sent.") - except Exception as e: - log(f"ERROR: Failed to reboot {ip}. Reason: {e}") - -def main(): - try: - with open(DEVICE_LIST) as f: - for line in f: - parts = line.strip().split() - if len(parts) != 3: - continue # skip malformed lines - ip, user, password = parts - reboot_device(ip, user, password) - except FileNotFoundError: - log(f"ERROR: Device list file not found: {DEVICE_LIST}") - sys.exit(1) - -if __name__ == "__main__": - main() \ No newline at end of file