Delete unifi_reboot.py

This commit is contained in:
2025-10-01 17:30:03 +00:00
parent 364185bee5
commit a4d03d0621
-45
View File
@@ -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()