Automatically enter input in command line

1

This question already has an answer here:

I need to automate the shell script, which have to send the values to a command prompt; the value1,value2 and value3 are in shell script Script1.sh. when I run this script in cmmand prompt, it will ask for ID, password and Item value, which are stored in this script.

My Script.sh:- !/bin/bash
SERVER1="13.xx.xx.132" #ip address third server
USERSERVER1=ubuntu #user conect to the server
PEMPATH="~/usr/abc.pem" #path to pamfile
Val1="123456"
Val2="abcd"
Val3="US"
Val4="text"
ssh -i $PEMPATH $USERSERVER1@$SERVER1
aws configure

In Commnad prompt:-

/home> ./Script1.sh #I run this
/home>Enter ID: #val1 needs to be entered
/home>Enter Password: #Val2 needs to be entered
/home>Enter Item: #Val3 needs to be entered
/home> cd /usr/

can any one give me a suggestion or any view to execute my...

0 0
2

I'm running a script that it requests entering 'y' on each operation, I am looking for a solution like $ ./script < echo 'yyyyyyyyyyyyyy' to pass all my inputs in one time.

There is a command created specifically for that case: yes

yes | ./script

If you want to say no (n) instead of yes (y) you can do it like this:

yes n | ./script

What yes does is it repeatedly prints y (or the argument if given) followed by a newline to stdout. If you connect the output of yes to another command using a pipe (the vertical bar) then the y followed by newline will go to the input of the other command.

Other methods to enter input:

If you know exactly how many y your script is expecting you can do it like this:

printf 'y\ny\ny\n' | ./script

Using printf instead of yes you have more fine grained control of input:

printf 'y\nyes\nno\nmaybe\n' | ./script

Note that in some rare cases the command does not require the user to press enter after the...

0 0
3

I need to automate the shell script, which have to send the values to a command prompt; the value1,value2 and value3 are in shell script Script1.sh. when I run this script in cmmand prompt, it will ask for ID, password and Item value, which are stored in this script.

My Script.sh:- !/bin/bash
SERVER1="13.xx.xx.132" #ip address third server
USERSERVER1=ubuntu #user conect to the server
PEMPATH="~/usr/abc.pem" #path to pamfile
Val1="123456"
Val2="abcd"
Val3="US"
Val4="text"
ssh -i $PEMPATH $USERSERVER1@$SERVER1
aws configure

In Commnad prompt:-

/home> ./Script1.sh #I run this
/home>Enter ID: #val1 needs to be entered
/home>Enter Password: #Val2 needs to be entered
/home>Enter Item: #Val3 needs to be entered
/home> cd /usr/

can any one give me a suggestion or any view to execute my...

0 0
4
The problem is that the program I need to manipulate runs in DOS. I can get DOS to execute a command like "DIR" and return the proper results. However, since the program I am using promts the user for inputs in the DOS window, I need a way to aotomatically navigate menu items in DOS from matlab. Any suggestions?? Neil O'Leary wrote: > > > Have a look at the dos command > > I'm not 100% sure about your second problem, why can't you just > take the > input commands out of the script? > > Edward Diggs wrote: >> I actually have two problems that are somewhat related. >> >> 1. I am trying to run an external program that uses the windows >> command line. I need to run it multiple times with the same > series of >> user inputs to the program. I would rather do this automatically, > but >> I do not know how to send commands to the windows command line > from a >> matlab script. Is this possible?? I can open the external program >> from matlab, but don't know how to go from there. >> >> 2. I...
0 0
5

The CHOICE command gives you the ability to set a default option after a specified time out:

CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text] Description: This tool allows users to select one item from a list of choices and returns the index of the selected choice. Parameter List: /C choices Specifies the list of choices to be created. Default list is "YN". /N Hides the list of choices in the prompt. The message before the prompt is displayed and the choices are still enabled. /CS Enables case-sensitive choices to be selected. By default, the utility is case-insensitive. /T timeout The number of seconds to pause before a default choice is made. Acceptable values are from 0 to 9999. If 0 is specified, there will be no pause and the default choice is selected. /D choice Specifies the default choice after nnnn seconds. Character must be in...
0 0
6
tfredett has asked for the wisdom of the Perl Monks concerning the following question:

Hello oh wise Perl monks. I have a question that I can not seem to find an answer to and I hope to take a sip from your fountain of knowledge.

I am currently writing a script that issues a system command and the command itself brings up a prompt like this after a few seconds

Do you want to read the file? 1 for yes, 2 for no. (Default is 2)

My question is how would I issue my script to say yes once this comes up? I have tried with the following code, but seem to be having issues, primarily where the if statement does execute correctly, however the issuance of the automated user response is far to late. This appears to be due to the script returning user control and halts and waits for the user to enter anything, including just pressing the enter key. Any help is appreciated!

$output = `Command foo`; print $output; if ($output = ~/Do you want to read the file?/) { ...

0 0
7

I am attempting to get the keyboard input for a command line app for the new Apple programming language Swift.

I’ve scanned the docs to no avail.

import Foundation println("What is your name?") ???

Any ideas?

Sending keyboard input to a program from command-line

How do you send keyboard input to a program? That is, under a Linux GUI, is there a good manual (programmable) way, or tool, of simulating keyboard input on a running program on Linux, so that I can s

creating avd from command line with keyboard support

How can I create avd from command line with keyboard support? I was able to create avd from commandline using: android create avd, but I dont know how to enable keyboard support into this. Even androi

Change keyboard input using Command Line

I would like to know whether is it possible to write a batch file that changes the default input language under windows XP What if the language is not installed ? For example,...

0 0
8

I know this has been asked before but almost only workarounds have been provided. None that solved my problem just yet.

I'm trying to create my own .sh file which will generate an apk. After using jarsigner it asks for a password of my keystore. Now the security on this part doesn't play a role a.t.m. so I was just wondering, how can I (either remove the password of my .keystore file or enter the password as plain text) achieve this?

The full command:

jarsigner -sigalg SHA1withRSA -digestalg SHA1 -verbose -keystore keyForApk.keystore apk/android-release-unsigned.apk alias_name

Where it then prompts me the following:

Enter Passphrase for keystore:

Now via which command can I enter this dynamically after the jarsigner...

0 0
9

I need to send some credentials defined in a file to a vpn connection command which is waiting for username and password to be entered when executed. There is a similar requirement to my question Automatically enter input in command line.

The following solution provided does work for me too:

printf 'username\npassword\n' | /usr/sbin/openconnect -i vpn0 ...

(executed inside a shell script). But I need to pass the credentials contained in a file (env_properties) and loaded as environment variables. I'm loading the file content using the following command:

[ -f env_properties] && . env_properties

The content looks as follows

export VPN_USERNAME=myUsername export VPN_PASSWORD=myPassword

However, such a construct doesn't work anymore:

printf "${VPN_USERNAME}\n${VPN_PASSWORD}\n" | /usr/sbin/openconnect -i vpn0 ...

It seems that the input isn't recognized correctly for whatever reason. And neither this command

printf "/usr/sbin/openconnect -i vpn0...
0 0
10

I know, my English is not good. Sorry for this. So I try to explain with an example.

I have to do it for 5-6 examples and I will show you one of them. If anyone know how to do logic and answer me, it will be nice.

String cmd = "openssl enc -aes-256-cbc -e -in " + path + " -out " + path+"_E"; Process pb = Runtime.getRuntime().exec(cmd); pb.waitFor();

If I enter this code in Terminal manually, it will ask me encryption password and I will be enter. After that, it ask me re-enter encryption password and I will be enter.

What I want is that, can I handle both enter and re-enter things from java code ? I want to enter automatically from java.

PS: I do not want to disable to use password! I want enter from java code.

Thanks for...

0 0