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
Related
I am using Git Bash on Windows.
I just verified my Heroku account,
then I open git bash and type:
$ heroku login
bash responds:
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/browser/c31ddaf9-7a55-4daf-afad-a0500e924c26
heroku: Waiting for login...
Logging in... done
Logged in as [my mail address]
and then, I can type whatever I want, but it does not get and execute the command, behaving like a text editor. Then, when I click on the cross to close it, a warning message appears, telling that some processes are still going on.
How do I unlock the freezing and go on using Bash?
I solved it by hitting CTRL+C to break out and chose yes (type y).
It turns out that the git bash terminal has the frequent problem of turning "frozen" after you enter a command.
Whenever it happens, you should press CTRL+C
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?
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 am trying to execute a remote command for one of my scripts. I have to run this script across many servers. so i will put it in a script. What I am trying to do is
ssh root#10.158.42.12 nohup perl /script/myscript.pl 06/04/2014 60 &
The script runs just fine but there is an info message which is displayed whenever you try to login . The one many of you would be familiar with ..
|-----------------------------------------------------------------|
| This system is for the use of authorized users only. |
| Individuals using this computer system without authority, or in |
Due to this the script execution is haulted unless an enter is pressed. I want to put the script in a cronjob for automatic execution, so i dont need to see this info message.
Here's my theory:
Your command doesn't run the program in the background on the server. It runs runs the program in the foreground on the server, and then you background ssh.
Since ssh runs in the background, you are immediately returned to your prompt.
Milliseconds later, ssh overwrites your prompt with this message and runs the command.
You are now looking at the ssh message and no prompt.
You hit press enter, which causes the prompt to be redrawn on the next line.
This leads you to believe ssh was actually waiting for you to press enter. In reality, the command was already run, and bash was ready for new commands, just obscured by ssh noise.
How to test:
If I'm right, pressing Ctrl+L instead of Enter will clear the screen and show the bash prompt. (assuming you don't use bash's vi mode).
If I'm not, Ctrl+L will instead either do nothing, print the ssh message again or just write ^L to the screen.
How to fix if I'm right:
ssh -f root#10.158.42.12 'nohup perl /script/myscript.pl 06/04/2014 60 &' 2> /dev/null
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?