From b09b3531d329c62879be626f840ffc59e4d9e89b Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Thu, 14 Nov 2024 14:11:40 -0700 Subject: [PATCH] Scripts: exec to psyncup --- bin/psyncup.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/psyncup.py b/bin/psyncup.py index 1545c77..1face57 100755 --- a/bin/psyncup.py +++ b/bin/psyncup.py @@ -55,6 +55,11 @@ parser.add_argument( action="store_true", help="Don't delete all non-matching files when rsyncing", ) +parser.add_argument( + "--exec", + type=str, + help="Run command on remote machine after sync", +) group = parser.add_mutually_exclusive_group(required=True) group.add_argument( @@ -252,6 +257,15 @@ def run_down(rsync_cmd, remote_dir_str): exit(1) +def run_exec(cmd, config): + if config.get("ssh_jump") is not None: + ssh_cmd = ["ssh", "-t", "-J", config["ssh_jump"], config["ssh_remote"], cmd] + else: + ssh_cmd = ["ssh", "-t", config["ssh_remote"], cmd] + + subprocess.run(["ssh", "-t", config["ssh_remote"], cmd]) + + if __name__ == "__main__": if args.init: run_init() @@ -269,6 +283,9 @@ if __name__ == "__main__": elif args.up: rsync_cmd, _, remote_dir_str = build_commands(args, config) run_up(rsync_cmd, remote_dir_str, config) + + if args.exec: + run_exec(args.exec, config) elif args.down: rsync_cmd, _, remote_dir_str = build_commands(args, config) run_down(rsync_cmd, remote_dir_str)