I'm writing a script that will fetch a list of database names from a server so the user knows which databases they can enter in the next prompt:
echo "FETCHING DB NAMES... (^C to skip)"
ssh "$user@$SERV_A" "$remote_cmd" #returns space-delim db list
echo
printf "Which db do you want to import? >"
read db_name
#rest of script
It looks like this to the user:
FETCHING DB NAMES... (^C to skip)
db1 db2 personnel
Which db would you like to import? >
The problem is that fetching those databases happens can take between 1-10 seconds depending on the connection. If the user already knows the db name, this can be frustrating.
Of course, pressing ^C
as the prompt indicates kills the entire script rather than just the ssh process. Is there a way I can write the script so they can cancel/skip just that ssh process?
Thank you in advance.
EDIT: it doesn't have to be ^C
per se, really just want to give the user a way to skip a running child process.