43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
|
|
import paramiko, time
|
||
|
|
|
||
|
|
c = paramiko.SSHClient()
|
||
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
|
|
c.connect("100.85.152.112", 22, "simon", "Nas82829330")
|
||
|
|
|
||
|
|
def run(cmd):
|
||
|
|
"""Execute SSH command and return stdout string"""
|
||
|
|
stdin, stdout, stderr = c.exec_command(cmd, timeout=10)
|
||
|
|
# Wait for command to finish
|
||
|
|
while not stdout.channel.exit_status_ready():
|
||
|
|
time.sleep(0.1)
|
||
|
|
out = stdout.read().decode("utf-8", errors="replace").strip()
|
||
|
|
err = stderr.read().decode("utf-8", errors="replace").strip()
|
||
|
|
return out, err
|
||
|
|
|
||
|
|
# Get report file list
|
||
|
|
out, err = run("ls /volume1/docker/gaokao-portal/nginx/html/reports/")
|
||
|
|
reports = [f for f in out.split("\n") if f.endswith(".html")]
|
||
|
|
|
||
|
|
# Test all pages
|
||
|
|
pages = ["/", "/report.html", "/questionnaire.html", "/results.html", "/css/style.css"]
|
||
|
|
pages += [f"/reports/{r}" for r in reports]
|
||
|
|
|
||
|
|
print("页面验证:")
|
||
|
|
for path in pages:
|
||
|
|
out, err = run(f"wget -q --spider http://localhost:8080{path} 2>&1 && echo OK || echo FAIL")
|
||
|
|
status = "OK" if "OK" in out else "FAIL"
|
||
|
|
print(f" [{status}] {path}")
|
||
|
|
|
||
|
|
# Container status
|
||
|
|
out, err = run("echo 'Nas82829330' | sudo -S /usr/local/bin/docker compose -f /volume1/docker/gaokao-portal/docker-compose.yml ps 2>/dev/null")
|
||
|
|
print("\n容器状态:")
|
||
|
|
for line in out.split("\n"):
|
||
|
|
if line.strip():
|
||
|
|
print(f" {line}")
|
||
|
|
|
||
|
|
# Count files
|
||
|
|
out, err = run("find /volume1/docker/gaokao-portal -type f | wc -l")
|
||
|
|
print(f"\n部署文件总数: {out}")
|
||
|
|
|
||
|
|
c.close()
|