40 lines
2.0 KiB
Python
Executable File
40 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import subprocess, os, json, re
|
|
results = {"scripts": [], "crons": [], "systemd": [], "logs_active": []}
|
|
|
|
# Find all scripts containing 'systemctl restart nginx' or similar
|
|
paths = ["/opt", "/usr/local/bin", "/usr/local/sbin", "/etc/cron.d", "/etc/cron.daily",
|
|
"/etc/cron.hourly", "/var/spool/cron", "/root", "/home"]
|
|
for p in paths:
|
|
if not os.path.exists(p): continue
|
|
try:
|
|
r = subprocess.run(f"grep -rln 'restart nginx\|reload nginx\|nginx.*restart\|systemctl.*nginx' {p} 2>/dev/null | head -20",
|
|
shell=True, capture_output=True, text=True, timeout=15)
|
|
if r.stdout.strip():
|
|
results["scripts"].extend([l for l in r.stdout.strip().split("\n") if l])
|
|
except: pass
|
|
|
|
# Check root crontab
|
|
r = subprocess.run("sudo crontab -u root -l 2>/dev/null | grep -v '^#' | grep -v '^$'",
|
|
shell=True, capture_output=True, text=True, timeout=5)
|
|
results["crons"] = [l for l in r.stdout.split("\n") if l.strip()]
|
|
|
|
# Check systemd timers
|
|
r2 = subprocess.run("systemctl list-timers --no-pager 2>/dev/null | head -20", shell=True, capture_output=True, text=True, timeout=5)
|
|
results["systemd"] = [l for l in r2.stdout.split("\n") if l.strip()][:15]
|
|
|
|
# Recent watchdog log activity
|
|
r3 = subprocess.run("ls -lt /var/log/*watchdog* /var/log/*fpm* 2>/dev/null | head -10", shell=True, capture_output=True, text=True, timeout=5)
|
|
results["logs_active"] = [l for l in r3.stdout.split("\n") if l.strip()][:10]
|
|
|
|
# Recent nginx restarts
|
|
r4 = subprocess.run("sudo journalctl -u nginx --since '1 hour ago' 2>/dev/null | grep -i 'reload\|restart\|stopped\|started' | tail -10",
|
|
shell=True, capture_output=True, text=True, timeout=10)
|
|
results["nginx_journal_1h"] = [l[-150:] for l in r4.stdout.split("\n") if l.strip()][:10]
|
|
|
|
# Find owner of phpfpm-watchdog.log
|
|
r5 = subprocess.run("sudo lsof /var/log/phpfpm-watchdog.log 2>/dev/null | head -5", shell=True, capture_output=True, text=True, timeout=5)
|
|
results["log_writer"] = r5.stdout.strip()[:500]
|
|
|
|
print(json.dumps(results, indent=2)[:5000])
|