I am currently writing a Dockerfile, and I one of the commands I want to execute requires the user to press [ENTER], for example:
Press [ENTER] to continue or Ctrl-c to cancel adding it.
I know that on some commands when it requires a [Y/n] the -y flag will suffice; however, in some commands such as this one, it requires a physical key press. Therefore, I would like you to please help me solve this issue.
How does one send a [ENTER] key press as a flag in a Dockerfile?
Related
Hello I am trying to write a bash script to launch QEMU in the background and wait for the user to press a key to continue with the script.
This is what I have currently:
setup_for_greengrass # these are functions
run_qemu & # fork function and try to run in the background
echo "Press anything to continue once VM is finished booting...\n"
read fullname # wait for user to press a key
install_greengrass
However, what I get in the terminal is the QEMU console and I am unable to keep moving forward with the script. If I fork the process and don't have the read command there, it works as expected and the QEMU console does not show up and the script keeps moving forward.
Any suggestions on how I could fork the QEMU process differently or wait for user input?
I figured it out... In bash version 4 or greater and zsh have support for this command called coproc.
https://www.geeksforgeeks.org/coproc-command-in-linux-with-examples/
https://stackoverflow.com/a/68407430/4397021
https://www.zsh.org/mla/users/2011/msg00095.html
So write the script as follows and it should launch the qemu in the background and let the script keep going forward.
#!/bin/zsh # Make sure to use zsh or upgrade your version of bash
setup_for_greengrass
coproc run_qemu # launch qemu in the background
echo "Press anything to continue once VM is finished booting...\n"
read fullname # wait for user to press a key
install_greengrass
I have a bash script that helps install a few applications automatically.
One app requests that I press ENTER to continue, or CTRL+C to cancel.
How can I automate my script to press ENTER when that prompt comes up?
For simple enter or confirmation, consider using the yes command:
yes '' | command_or_script
For automating more complex interactions, consider using expect.
See: https://stackoverflow.com/a/7013379/7939871
I'm trying to make iTerm give me a notification whenever a command I run in an SSH session completes. To do this, I set marks whenever I run a command which notifies me whenever the command completes. However, it seems like I can't set when I am ssh'd into a server—the eye appears, but nothing happens when the command has been completed. How would I go about doing this?
Is it possible to enter keyboard shortcuts into a bash script? For example, I have tried typing in ^d to substitute for control + d (logout) without success.
ubuntu#vfleet:~$ ^d
-bash: :s^d: substitution failed
ubuntu#vfleet:~$ ^D
-bash: :s^D: substitution failed
I am using screen to run a django development server in the background. One of the commands to run a particular screen as a daemon is control + a + d. The goal is to be able to enter in control + a + d into a bash script. For example:
python manage.py runserver
^a + d
Is this possible?
Edit:
A valid method of avoiding the keyboard shortcut in screen is linked by Eric Renouf in the comments below. screen -d -m sh -c "python manage.py runserver" will start a development server as a daemon. This is a great solution for my particular problem, but it would still be nice to have a solution for the original question at hand.
xdotool package is the solution here.
xdotool key ctrl+d
Full reference
You probably should just start the command without attaching to the screen session in the first place, like
screen -d -m python manage.py runserver
but if you can't do that for some reason, you could detach from a screen session you're currently in by doing:
screen -S "$STY" -X detach
screen saves its current session info in STY, so we'll use that to make sure we're interacting with the correct session (in case there are many). Then we'll use -X to send a command to that session, in this case our command will be detach which will detach all the attached sessions, including the one used to execute that command
So while this doesn't actually send key strokes, it does highlight that there is often another command that you can send to accomplish your goals. Here detach takes the place of ctrl+a+d. Sending quit or running exit could often replace ctrl+d.
Another work-around would be to use expect which you could then use to send the strings containing control characters or hex values of them.
I'm trying to use capistrano to deploy on a shared host. However the ssh connection seems not to be standard, when I connect with the terminal, it asks me to press Enter to continue, and this seems to prevent Capistrano from working. Here's the console output:
Asking for console, please wait
Connected
Grabbing terminal
Ok
Press [Enter] to start a shell
hosting-user#paas_12345:~$
Any idea on how I could hack Capistrano to press the Enter key just after login? Or at least some ideas about what this strange terminal technology is?