Os multiplexadores de terminal tmux
e screen
são frequentemente usados para isso.
session=$RANDOM tmux new-session -s "$session" -d "ssh foohost" tmux split-window -t "$session:0" tmux send-keys -t "$session:0.1" "cd workdir" "Enter" tmux attach -t "$session"
session=screen-$RANDOM screen -dmS "$session" screen -S "$session" -X ...I gave up.