Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to send keyboard inputs toa UNIX command executed from a shell script? Post 302874753 by wisecracker on Saturday 16th of November 2013 07:03:22 PM
Old 11-16-2013
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...
Code:
#!/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/test.sh
echo -e 'if [ "$wait_for_yes" == "y" ]' >> /tmp/test.sh
echo -e "then" >> /tmp/test.sh
echo -e "        echo 'Y was detected...'" >> /tmp/test.sh
echo -e "fi" >> /tmp/test.sh
echo -e 'if [ "$wait_for_yes" == "n" ]' >> /tmp/test.sh
echo -e "then" >> /tmp/test.sh
echo -e "        echo 'Auto N was detected...'" >> /tmp/test.sh
echo -e "fi" >> /tmp/test.sh
chmod 755 /tmp/test.sh
echo -e "Launch this command test.sh...\n"
/tmp/test.sh
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 test.sh...\n"
echo -n "n" > /tmp/Y
/tmp/test.sh
echo -e "\nReturn back to the calling shell..."
rm /tmp/Y

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

Y was detected...

Return back to the calling shell...

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

Auto N was detected...

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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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" emailid@org.com < $ProcessStatisticsFile fi Please help me... (5 Replies)
Discussion started by: sreelu
5 Replies

6. 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

7. 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

8. 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

9. UNIX for Beginners Questions & Answers

UNIX Shell Script to Remove MongoDB Document-Based on Many inputs

Here I am in a position to write a Unix Shell script(.sh) to remove MongoDB collection documents. I know how to remove based on a condition like below and it works for me. eval 'db.Collection.remove({TimeStamp:{$lte: "'$var'"}}) But I need to change the remove statement based on a new parameter... (1 Reply)
Discussion started by: senthilmadhanT
1 Replies

10. UNIX for Beginners Questions & Answers

Shell script to check a command executed sucessfully or not

Hi All, I am trying to write a shell script to check if a command executed successfully or not in rhel 7 and finding the installed tomcat version. I am using below script. var4=$(find / -name "catalina.jar" ! -size 0 |egrep -v... (6 Replies)
Discussion started by: sravani25
6 Replies
line(1) 						      General Commands Manual							   line(1)

NAME
line - Reads one line from standard input SYNOPSIS
line STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: line: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None DESCRIPTION
The line command copies one line, up to and including a newline, from standard input and writes it to standard output. Use this command within a shell command file to read from your terminal. The line command always writes at least a newline character. NOTES
The line utility has no internationalization features and is marked LEGACY in XCU Issue 5. Use the read utility instead. EXIT STATUS
Success. End-of-File. EXAMPLES
To read a line from the keyboard and append it to a file, enter: echo 'Enter comments for the log:' echo ': c' line >>log This shell procedure displays the message: Enter comments for the log: It then reads a line of text from the keyboard and adds it to the end of the file log. The echo ': c' command displays a : (colon) prompt. See the echo command for information about the c escape sequence. SEE ALSO
Commands: echo(1), ksh(1), read(1), Bourne shell sh(1b), POSIX shell sh(1p) Functions: read(2) Standards: standards(5) line(1)
All times are GMT -4. The time now is 11:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy