50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Hlida serverovy log (na Unraidu) dokud dany beh neskonci.
|
|
Poluje pres SSH, tiskne ridky progress, skonci na koncovem markeru.
|
|
Pouziti: _watch_server_log.py <vzdalena_cesta_logu> [marker]
|
|
"""
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
HOST = "192.168.1.76"
|
|
USER = "root"
|
|
PASS = "7309208104"
|
|
|
|
logpath = sys.argv[1] if len(sys.argv) > 1 else "/mnt/user/Scripts/MailStore/dryrun_full.log"
|
|
marker = sys.argv[2] if len(sys.argv) > 2 else "Zprav proskenovano"
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=10)
|
|
|
|
|
|
def sh(cmd):
|
|
i, o, e = c.exec_command(cmd)
|
|
return o.read().decode("utf-8", "replace")
|
|
|
|
|
|
t0 = time.time()
|
|
last_count = -1
|
|
while True:
|
|
content = sh(f"cat {logpath!r} 2>/dev/null")
|
|
done = (marker in content) or ("Traceback" in content)
|
|
folders = content.count("k dobrani=")
|
|
if folders != last_count:
|
|
mins = (time.time() - t0) / 60
|
|
# posledni zpracovana slozka
|
|
lines = [l for l in content.splitlines() if "k dobrani=" in l]
|
|
last = lines[-1].strip() if lines else ""
|
|
print(f"[{mins:4.1f} min] slozek hotovo: {folders:4} | {last[:70]}", flush=True)
|
|
last_count = folders
|
|
if done:
|
|
print("=== HOTOVO ===", flush=True)
|
|
tail = "\n".join(content.splitlines()[-10:])
|
|
print(tail, flush=True)
|
|
break
|
|
time.sleep(30)
|
|
|
|
c.close()
|