From a9454db32fb5920f425bb4fe1ffb395dc180a5e1 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 22 Mar 2023 13:24:58 +0100 Subject: [PATCH] Adding port customisation --- README.md | 5 +++-- remotes/root@example.org/port | 1 + run_all.sh | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 remotes/root@example.org/port diff --git a/README.md b/README.md index 841b3a4..8eee8b9 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ This script has several dependencies: First of all, you will need create the scripts that will be executed on the remote servers. 1. Head to the `remotes` directory 2. Create a new directory named using the `user`@`host` pattern for the remote host and the user on it you want to execute the script on. (e.g: `root@example.org`) if it does not exist. -3. Create a new script (the file name will be used as script name when it's executed at runtime). -4. (optional) You can import common libraries by adding a comment on line two following this pattern : `# Requires: libraries/.sh`. You can import several libraries by separating them by a space. You can see the various default included libraries in the `libraries` directory. +3. Create a file `port` with the SSH port number. +4. Create a new script (the file name will be used as script name when it's executed at runtime). +5. (optional) You can import common libraries by adding a comment on line two following this pattern : `# Requires: libraries/.sh`. You can import several libraries by separating them by a space. You can see the various default included libraries in the `libraries` directory. **Note**: The libraries/common.sh library will always be imported into the server so you don't need to reference it there. diff --git a/remotes/root@example.org/port b/remotes/root@example.org/port new file mode 100644 index 0000000..2bd5a0a --- /dev/null +++ b/remotes/root@example.org/port @@ -0,0 +1 @@ +22 diff --git a/run_all.sh b/run_all.sh index 5669a89..1ac3abd 100755 --- a/run_all.sh +++ b/run_all.sh @@ -48,6 +48,7 @@ for folder in "$REMOTES"/*; do echo -e "\n" dependencies="libraries/common.sh" full_script="" + port="$(cat $folder/port)" # Executing all necessary scripts if [[ $pswd != "skip" ]]; then for script in $folder/*.sh; do @@ -72,11 +73,12 @@ $full_script" export SSH_ASKPASS="$(pwd)/tmp.sh" export SSH_ASKPASS_REQUIRE="force" # Transmit the script - echo "$full_script" | ssh -q $host "tee run.sh" 1>/dev/null + echo "$full_script" | ssh -q $host -p $port "tee run.sh" 1>/dev/null info "Transmitted script" # Run and remove it. - #ssh $host PASSWORD="$pswd" "bash run.sh && rm run.sh" - ssh -t $host PASSWORD="$pswd" "bash -i run.sh && rm run.sh" + ssh $host -p $port PASSWORD="$pswd" "bash run.sh && rm run.sh" + ## Interactive shell does not work. + #ssh -t $host PASSWORD="$pswd" "bash -i run.sh && rm run.sh" rm tmp.sh else box "Skipping ${host}..."