The script is a bit sensitive, so I'll hide some details, but the script runs up to the > mark
auth="$(mariadb -N -h $DBHOST -P $DBPORT $DBNAME -e "SELECT ..... -u $DBUSER -p$DBPASS)"
> ssh -i /root/.ssh/ssh_host_ed25519_key -oStrictHostKeyChecking=accept-new "IP" "do $auth"
export GFS="IPS"
for ip2 in $GFS; do ufw allow from $ip2; done
for ip2 in $GFS; do ssh -i /root/.ssh/ssh_host_ed25519_key -oStrictHostKeyChecking=accept-new -n "$ip2" "ufw allow from $MYIP"; done
...
The ssh command executes without error, then script just stops. Even with bash -x I can't see anything wrong.
It's even weirder because this only happens in the full script, if I create a test script with just the needed variables, and the same code, it runs fine.
How to debug this?
>
, redirecting the-i
command into a file calledssh
? – Kusalananda Jan 09 '22 at 10:31set -e
disabled and check the exit status of thessh
, e.g.echo "ssh exited with status $?"
on the next line. Or if you need to keepset -e
on, change it tossh ... | true
(with the pipe), and check${PIPESTATUS[0]}
instead of$?
on the next line (in Bash only, though). I'm not sure if there's something missing, but it looks like you're passing"do $auth"
as the command forssh
to run on the remote, and that's likely to give a syntax error on the remote, if there's a regular shell there. Where your errors go, well, that I can't know. – ilkkachu Jan 09 '22 at 10:42ssh
line, then thefor
loops after it are rather irrelevant for the issue, no? Creating a script with only the relevant parts is the right approach, but if the problem doesn't appear with such a reduced script, ...well, then it didn't contain all the relevant parts and you need to try something else. Start by removing everything after the part where it stops to reduce distractions. Then look at what the failing command relies on, and remove everything else. If it stops failing, you removed something that was important to issue. – ilkkachu Jan 09 '22 at 10:46