commit message from python script

This commit is contained in:
2024-02-19 18:05:34 +01:00
parent ce15671c64
commit 29431b3786

View File

@@ -1,31 +1,34 @@
#! /home/jonnybravo/Projekte/Python_Skripte/rclone/bin/python3.11 #! /usr/bin/env python3
import os, time import os, time, subprocess
def check_ping(hostname = str): def check_ping(hostname = str):
response = os.system("timeout 0.2 ping -c 1 " + hostname + '&> /dev/null') list_command = list(str('timeout 0.2 ping -c 1 ' + hostname).split())
response = subprocess.run(list_command, stdout=subprocess.PIPE)
# and then check the response... # and then check the response...
if response == 0: if response.returncode == 0:
return True return True
else: else:
return False return False
def rclone_folders_copy(folder_to_sync=list, dest_folder = str): def rclone_folders_copy(folder_to_sync=list, dest_folder = str):
check_list = [] check_list = []
for sync_folder in folder_to_sync: for sync_folder in folder_to_sync:
print("Hole Datein", 'rclone:' + sync_folder, "...") print("Hole Datein", 'rclone:' + sync_folder, "...")
command = os.system('rclone copy rclone:' + sync_folder + ' ' + dest_folder + os.sep + sync_folder +' --update --create-empty-src-dirs &> /dev/null') list_command = list(str('rclone copy rclone:' + sync_folder + ' ' + dest_folder + os.sep + sync_folder + ' --update --create-empty-src-dirs').split())
if command == 0: command = subprocess.run(list_command, stdout=subprocess.PIPE)
if command.returncode == 0:
check_list.append(True) check_list.append(True)
elif command > 0: elif command > 0:
check_list.append(False) check_list.append(False)
print("Folder", "rclone:" + sync_folder , "not exist") print("Folder", "rclone:" + sync_folder , "not exist")
print("Kopiere Datein", dest_folder + os.sep + sync_folder, "..." ) print("Kopiere Datein", dest_folder + os.sep + sync_folder, "..." )
command = os.system('rclone copy ' + dest_folder + os.sep + sync_folder + ' ' + "rclone:" + sync_folder + ' --update --create-empty-src-dirs &> /dev/null' )
if command == 0: list_command = list(str('rclone copy ' + dest_folder + os.sep + sync_folder + ' ' + "rclone:" + sync_folder + ' --update --create-empty-src-dirs').split())
command = subprocess.run(list_command, stdout=subprocess.PIPE)
if command.returncode == 0:
check_list.append(True) check_list.append(True)
elif command > 0: elif command.returncode > 0:
check_list.append(False) check_list.append(False)
print("Folder", dest_folder + os.sep + sync_folder , "not exist") print("Folder", dest_folder + os.sep + sync_folder , "not exist")
for check in check_list: for check in check_list:
@@ -33,11 +36,9 @@ def rclone_folders_copy(folder_to_sync=list, dest_folder = str):
return False return False
return True return True
if __name__ == "__main__": if __name__ == "__main__":
nextcloud_server = "schlaubistechtalk.de" nextcloud_server = "schlaubistechtalk.de"
folder_to_sync_manuell = ['ssh_keys', 'frei', 'Doku','Joplin', 'Hack'] folder_to_sync_manuell = ['frei']
print("Check online status von", nextcloud_server) print("Check online status von", nextcloud_server)
for check_count in range(1,10): for check_count in range(1,10):
if check_ping(hostname=nextcloud_server) is True: if check_ping(hostname=nextcloud_server) is True: