mirror of
https://gitlab.sectorq.eu/jaydee/python.git
synced 2025-12-14 02:34:53 +01:00
bitwarden
This commit is contained in:
@@ -9,12 +9,21 @@ import subprocess
|
||||
import sys
|
||||
import os
|
||||
import platform
|
||||
from wakeonlan import send_magic_packet
|
||||
pid = os.getpid()
|
||||
|
||||
host = platform.node().lower()
|
||||
cmnd = "ps -ef|grep omv_backups.py|grep -v grep |grep -v {}|wc -l".format(pid)
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
|
||||
def is_port_open(host, port):
|
||||
try:
|
||||
sock = socket.create_connection((host, port))
|
||||
sock.close()
|
||||
return True
|
||||
except socket.error:
|
||||
return False
|
||||
|
||||
print(output)
|
||||
if int(output) > 0:
|
||||
print("Running already!")
|
||||
@@ -83,16 +92,32 @@ if not host in backups:
|
||||
print(f"No backup jobs for {host}")
|
||||
sys.exit()
|
||||
print("Test connection")
|
||||
try:
|
||||
|
||||
hm = socket.gethostbyaddr("omv.home.lan")
|
||||
HOST_UP = os.system(f"ping -c 1 -w 2 omv.home.lan") == 0
|
||||
print(HOST_UP)
|
||||
if not HOST_UP:
|
||||
print("Backup host down")
|
||||
send_magic_packet('88:c9:b3:b5:23:d8')
|
||||
|
||||
hostdown = True
|
||||
while hostdown:
|
||||
HOST_UP = os.system(f"ping -c 1 -w 2 omv.home.lan") == 0
|
||||
if not HOST_UP:
|
||||
print("Backup host down, waiting")
|
||||
time.sleep(5)
|
||||
else:
|
||||
print("host up")
|
||||
hostdown = False
|
||||
host = "omv.home.lan"
|
||||
port = 22 # Replace with the port you want to test
|
||||
if is_port_open(host, port):
|
||||
print(f"Port {port} on {host} is open.")
|
||||
else:
|
||||
print(f"Port {port} on {host} is closed.")
|
||||
sys.exit()
|
||||
except socket.herror:
|
||||
print("Unknown host")
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
for b in backups[host]:
|
||||
topic = "sectorq/omv/backups/{}".format(b.lower())
|
||||
|
||||
Reference in New Issue
Block a user