As part of a series of tasks I have to do, I have to build a bash script that accesses a remote computer, executes 3 commands, waits for a process to end through a SIGINT
(or simply end) and then do some cleanup afterwards.
Currently, I'm using this code:
#! /bin/bash
# local preparations
# ...
ssh -t $USER@remote.far <<-'COMMANDS'
echo "Preparing execution"
java -jar execute.jar &
executePID=$!
echo "Ready."
echo "CTRL+C to clean and close"
trap "kill $executePID" INT HUP
wait $executePID
#cleanup code here
echo "done. Logging out"
sleep 2
logout
COMMANDS
# Final local cleanup
This code seem to work just find until wait
(builtin) command. wait
seems to be consuming all commands that come after it and so, when I try to send a SIGINT
(Ctrl+C), it seems to fail to execute the trap content and all the cleanup code.
How can I fix this so it works the way I expect?
I'm not allowed to split this bash file into multiple ones and I'm not allowed to create any scripts on the remote computer even if temporary.
Both computers are running the same flavor of Linux.
No comments:
Post a Comment