How to send keyboard inputs toa UNIX command executed from a shell script?

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to send keyboard inputs toa UNIX command executed from a shell script?
# 1  
How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script?
# 2  
read v; echo "$v"

read v << EOF
echo "$v"

# 3  
Hi Sree10...

With your vague request I assume that your command is a native executable for the platform you are on.

As we cannot possibly know this command then a man page might show a flag to quench the Y input request and force an automatic continuation.

At this point I ask that you give us more information:-

1) OS.
2) Shell in use.
3) Terminal type, optional.
4) Machine, platform.
5) The special command.
6) And finally your attempts <- assuming it is possible in the first palce.

Help us, and we will attempt solutions.
# 4  
I am trying to run this on a Linux host. I have a customized shell script which when run prompts for some inputs. When i run this script manually from the command line, I can specify the input as y from the keyboard.
If this is correct, enter 'y':

But, when how do I invoke the same shell script from another shell script and pass y as an input.
# 5  
Hi Sree10...

Once again as we have no idea about your shell scripts nor commands then I have
created a very dirty example using a shell script generated on the fly awaiting a
physical "y" to be entered and an automatic "n" later, done longhand...
You will have to work out any subtleties, loops etc for yourself...
#!/bin/bash --posix
# An example ONLY...
> /tmp/Y
echo "Test for a remote Y on another shell script..."
echo -n "Enter y to continue:- "
read y
echo -n "$y" > /tmp/Y
echo -e "read wait_for_yes < /tmp/Y" > /tmp/
echo -e 'if [ "$wait_for_yes" == "y" ]' >> /tmp/
echo -e "then" >> /tmp/
echo -e "        echo 'Y was detected...'" >> /tmp/
echo -e "fi" >> /tmp/
echo -e 'if [ "$wait_for_yes" == "n" ]' >> /tmp/
echo -e "then" >> /tmp/
echo -e "        echo 'Auto N was detected...'" >> /tmp/
echo -e "fi" >> /tmp/
chmod 755 /tmp/
echo -e "Launch this command\n"
echo -e "\nReturn back to the calling shell...\n"
echo "Check using N for the remote entry but not inputted manually..."
echo -e "Launch this command\n"
echo -n "n" > /tmp/Y
echo -e "\nReturn back to the calling shell..."
rm /tmp/Y

Results on OSX 10.7.5, default bash terminal...
Last login: Sat Nov 16 23:41:57 on ttys000
AMIGA:barrywalker~> chmod 755
AMIGA:barrywalker~> ./
Test for a remote Y on another shell script...
Enter y to continue:- y
Launch this command

Y was detected...

Return back to the calling shell...

Check using N for the remote entry but not inputted manually...
Launch this command

Auto N was detected...

Return back to the calling shell...
AMIGA:barrywalker~> _


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #882
Difficulty: Easy
In October 2013 National Geographic released a file titled American Blackout which dealt with an imagined large-scale cyber attack on SCADA and the US electrical grid.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need command to capture word from shell script and send email

Hello Experts, Greeting to all of you. I have a requirement, that we have a shell script that check the status of server and server status shows as Enterprise Server - Running Admin Server - Shutdown Requirement is like whenever the output shows shutdown it should... (2 Replies)
Discussion started by: aks_1902
2 Replies

2. Shell Programming and Scripting

awk command not getting executed in shell script

I am able to execute awk command from shell prompt. but the same command is not getting executed when written and run in a bash script the command from bash cmd prompt. awk '/world/{for (i=2; i<NF; i++) printf $i " "; print $NF}1' myfile >tmp$$ ; mv tmp$$ myfile file: # hello world my... (4 Replies)
Discussion started by: ashima jain
4 Replies

3. Shell Programming and Scripting

Unable to pass send command in shell script

I am trying to automate a testcase . I am installing some software and it waits for user input after displaying "Do you want to continue ? " I am trying to do this in shell scripting. #!/bin/bash #!/usr/bin/expect -f /usr/bin/expect << EOF spawn apt-get install openjdk-7-jdk expect "*Do you... (1 Reply)
Discussion started by: Abdul Navaz
1 Replies

4. Programming

Some error with number of keyboard inputs occured with this code for reversing a string..

i used a two-way linked list "node" for the code:: #include<stdio.h> #include<malloc.h> void insert(); void reverse(); struct node { char c; struct node *next; struct node *back; }*start=NULL; int main() { int n,i; (4 Replies)
Discussion started by: mscoder
4 Replies

5. Shell Programming and Scripting

How to send email once a day at certain time in unix shell script

hi, i have to send an email once a day at ceratin time say 22. i have tried with date commad, but not working.:( HOUROFTHEDAY=`date +'%H'` if ; then mailx -s "Info" < $ProcessStatisticsFile fi Please help me... (5 Replies)
Discussion started by: sreelu
5 Replies

6. Shell Programming and Scripting

How can I send the input of a read line command through a shell script

Hi All, I wish to automate the unix command 'su' through a shell script. I would like to pass the content of a file as password to 'su' command. My script is as below, #! /bin/sh su userA while read line do rpm -ivh $line done < pwd.txt where pwd.txt contains the password of... (6 Replies)
Discussion started by: little_wonder
6 Replies

7. UNIX for Dummies Questions & Answers

Help how replace stardard keyboard inputs by arguments at run time of a script

Hello Everybody, Please help. I was trying to automate the use of a third-party given shell script. The script is written to be used at run-time to collect a few variables to be provided by the user through key board, in the fashion as below: ./runcommand please provide a file name to... (6 Replies)
Discussion started by: Dingrong
6 Replies

8. Shell Programming and Scripting

perl - why is the shell script executed before the print command?

i'm writing some simple scripts to help me learn perl. why does the print command get called after the shell script is executed? the purpose of the shell script is to simply echo to the screen "script run". which is does, but before the print command, you can clearly see the shell script is... (3 Replies)
Discussion started by: mjays
3 Replies

9. UNIX for Advanced & Expert Users

Unix shell Script To Send SMS

hi , can anyone help with a script to send SMS to some mobile numbers on some conditions. (1 Reply)
Discussion started by: sdcoms
1 Replies

10. Shell Programming and Scripting

Unix shell script couldn't be executed. Pls help!

I have wrriten a script to call sql script to do some work in database. However, the script couldn't be executed. The only information was: ksh: ./updt_attrib.ksh cannot execute. Please help me to identify where the problem is. I post script here for your reference. Thanks a lot. #!/bin/ksh ... (8 Replies)
Discussion started by: duke0001
8 Replies

Featured Tech Videos