tmux send-keys confirm ssh tunnel is closed (after sending multiple commands to the remote host) before proceeding
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.
LocalCommand doesn't do this.
here's the question:
After:
1. opening a new tmux session
2. using send-keys to establish an ssh tunnel
3. sending multiple commands to the remote host using send-keys
4. closing the ssh tunnel using send-keys
How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?
shell-script ssh tmux wait
add a comment |
up vote
0
down vote
favorite
there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.
LocalCommand doesn't do this.
here's the question:
After:
1. opening a new tmux session
2. using send-keys to establish an ssh tunnel
3. sending multiple commands to the remote host using send-keys
4. closing the ssh tunnel using send-keys
How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?
shell-script ssh tmux wait
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.
LocalCommand doesn't do this.
here's the question:
After:
1. opening a new tmux session
2. using send-keys to establish an ssh tunnel
3. sending multiple commands to the remote host using send-keys
4. closing the ssh tunnel using send-keys
How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?
shell-script ssh tmux wait
there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.
LocalCommand doesn't do this.
here's the question:
After:
1. opening a new tmux session
2. using send-keys to establish an ssh tunnel
3. sending multiple commands to the remote host using send-keys
4. closing the ssh tunnel using send-keys
How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?
shell-script ssh tmux wait
shell-script ssh tmux wait
edited Nov 28 at 15:18
asked Nov 28 at 15:06
p4ndepravity
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
How I ended up solving this:
rm ~/sesh.lock 2> /dev/null # in case of previous failure
tmux new-session -d -s sesh
tmux send-keys -t sesh "ssh prod-srv-1" Enter
tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
tmux send-keys -t sesh exit Enter
while [ ! -e ~/sesh.lock ]
do
tmux send-keys -t sesh "touch ~/sesh.lock" Enter
sleep 0.1
done
tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter
tmux kill-session -t sesh
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
How I ended up solving this:
rm ~/sesh.lock 2> /dev/null # in case of previous failure
tmux new-session -d -s sesh
tmux send-keys -t sesh "ssh prod-srv-1" Enter
tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
tmux send-keys -t sesh exit Enter
while [ ! -e ~/sesh.lock ]
do
tmux send-keys -t sesh "touch ~/sesh.lock" Enter
sleep 0.1
done
tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter
tmux kill-session -t sesh
add a comment |
up vote
0
down vote
How I ended up solving this:
rm ~/sesh.lock 2> /dev/null # in case of previous failure
tmux new-session -d -s sesh
tmux send-keys -t sesh "ssh prod-srv-1" Enter
tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
tmux send-keys -t sesh exit Enter
while [ ! -e ~/sesh.lock ]
do
tmux send-keys -t sesh "touch ~/sesh.lock" Enter
sleep 0.1
done
tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter
tmux kill-session -t sesh
add a comment |
up vote
0
down vote
up vote
0
down vote
How I ended up solving this:
rm ~/sesh.lock 2> /dev/null # in case of previous failure
tmux new-session -d -s sesh
tmux send-keys -t sesh "ssh prod-srv-1" Enter
tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
tmux send-keys -t sesh exit Enter
while [ ! -e ~/sesh.lock ]
do
tmux send-keys -t sesh "touch ~/sesh.lock" Enter
sleep 0.1
done
tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter
tmux kill-session -t sesh
How I ended up solving this:
rm ~/sesh.lock 2> /dev/null # in case of previous failure
tmux new-session -d -s sesh
tmux send-keys -t sesh "ssh prod-srv-1" Enter
tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
tmux send-keys -t sesh exit Enter
while [ ! -e ~/sesh.lock ]
do
tmux send-keys -t sesh "touch ~/sesh.lock" Enter
sleep 0.1
done
tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter
tmux kill-session -t sesh
answered Nov 28 at 15:16
p4ndepravity
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484687%2ftmux-send-keys-confirm-ssh-tunnel-is-closed-after-sending-multiple-commands-to%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown