-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.py
More file actions
executable file
·39 lines (32 loc) · 1.5 KB
/
watcher.py
File metadata and controls
executable file
·39 lines (32 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import time
import sys
def RsyncCommand(ssh_id, aix_usr, aix_host, ssh_dir, rsync_cmd="~/.sshfs/command.txt"):
cmd = f'rsync -avz -e "ssh -i {ssh_id}" {aix_usr}@{aix_host}:{rsync_cmd} {ssh_dir}'
print(f"Executing command: {cmd}")
os.system(cmd)
old_commnd = None
if __name__ == "__main__":
# Correct argv indexing and default handling
aix_usr = sys.argv[1] if len(sys.argv) > 1 else "root"
aix_host = sys.argv[2] if len(sys.argv) > 2 else "ulsur.pok.stglabs.ibm.com"
aix_isa_id = sys.argv[3] if len(sys.argv) > 3 else os.path.expanduser("~/.ssh/id_rsa_ulsur")
ssh_dir = sys.argv[4] if len(sys.argv) > 4 else os.path.expanduser("~/.sshfs")
print(f"Using AIX User: {aix_usr}, Host: {aix_host}, SSH ID: {aix_isa_id}, SSH Directory: {ssh_dir}")
while True:
RsyncCommand(aix_isa_id, aix_usr, aix_host, ssh_dir)
if not os.path.exists("command.txt"):
print("command.txt does not exist, waiting for next check...")
time.sleep(5)
continue
# Future command execution logic (kept commented as in your code)
# with open("command.txt", "r") as fp:
# new_command = fp.read().strip()
#
# if old_commnd != new_command:
# print(f"Executing command: {new_command}")
# old_commnd = new_command
# RsyncCommand(new_command)
# else:
# print("No new command found in command.txt, waiting...")
time.sleep(1) # Short wait before checking again