shell script executes program, but waits for a prompt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script executes program, but waits for a prompt
# 1  
Old 06-18-2008
shell script executes program, but waits for a prompt

Sorry, newbie here. I have the following shell script which basically executes the sh-n-body.i686 program a specified number of times. However, before the sh-n-body.i686 begins its calculations it prompts for input from the user. In this case the user would have press ". return" and sh-n-body.i686 will continue running. However, I just want the code to run about 100 times without having to enter . return. How can I modify the shell script so that it takes care of the prompt( . return).

#!/bin/sh
COUNTER=0
while [ $COUNTER -lt 100 ]; do
./sh-n-body.i686 56 3 32 0.02 1 -2 | grep "longest shadow"
let COUNTER=COUNTER+1
done

Thank you
# 2  
Old 06-18-2008
Code:
echo . | ./sh-n-body.i686 56 3 32 0.02 1 -2 | grep "longest shadow"

# 3  
Old 06-18-2008
the above code just results in a . after the sh-n-body has finished. I still get the prompt:

"Enter comment, ^D or . to end."

and still have to enter ". return" for the code to continue.
# 4  
Old 06-18-2008
Do you have access to the source code, or perhaps even the ability to change it? Perhaps it's reading /dev/tty rather than stdin, or something similarly inconvenient.
# 5  
Old 06-18-2008
Quote:
Originally Posted by lionatucla
the above code just results in a . after the sh-n-body has finished. I still get the prompt
The ./sh-n-body.i686 script is expecting the input, not the script that you showed in the example.
Somewhere in the script, there is probably a 'read' statement. Looks like this perhaps:

Code:
read value

When you enter your input, it gets stored in $value.
Only thing you have to do is manually assign your input to $value, like so:

Code:
value="your input here"

# 6  
Old 06-18-2008
I do have the source code, but I hesitate to change it. Here is the portion that has the prompt

fputs("Enter comment, ^D or . to end.\n", stderr);
puts("Comment:");
while(fgets(_line, sizeof(_line), stdin) && _line[0] != '.')
fputs(_line, stdout);
puts("");
# 7  
Old 06-18-2008
I don't know if it makes a difference but ./sh-n-body.i686 is a c file not a shell script.


Quote:
Originally Posted by lionatucla View Post
the above code just results in a . after the sh-n-body has finished. I still get the prompt
The ./sh-n-body.i686 script is expecting the input, not the script that you showed in the example.


Somewhere in the script, there is probably a 'read' statement. Looks like this perhaps:

Code:

read value

When you enter your input, it gets stored in $value.
Only thing you have to do is manually assign your input to $value, like so:

Code:

value="your input here"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Will shell script executes in sequence

I have a shell script scheduled in cron job to run at every 1 minute which transfers files to remote machine and then move the files to backup folder. cd /u01/app/ftp_tmp sftp user@hostname <<-EOF cd /home/user/ftp mput * bye EOF mv /u01/app/ftp_tmp/* /u01/app/ftp_bkp Now the problem is... (6 Replies)
Discussion started by: Bhavi
6 Replies

2. Shell Programming and Scripting

Script that waits for process to complete

Hello, I am in need of running an executable provided by a vendor that basically syncs files to a db. This tool can only be run against one folder at a time and it cannot have more than one instance running at a time. However, I need to run this tool against multiple folders. Each run of the... (5 Replies)
Discussion started by: vipertech
5 Replies

3. Homework & Coursework Questions

Shell Script Password Prompt

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to write a shell script that prompts the user for the password which is "lux" once the correct password... (4 Replies)
Discussion started by: Emin_Em
4 Replies

4. Shell Programming and Scripting

Shell script not getting called through cron job but executes fine manually.

Hi, My shell script not getting called through cron job. The same works fine when executed manually. I tried to generate logs to find if the scripts has some errors related to path using following command- trying to execute .sh file every 5 mins: */5 * * * * /home/myfolder/abc.sh... (17 Replies)
Discussion started by: Dejavu20
17 Replies

5. Shell Programming and Scripting

Help to hide shell terminal and run prompt program after ssh login for specified user

Hey guys, I have some task from my office to lock user on the specified directory after the user logged on using ssh. And then run prompt program to fill the required information. Yeah, just like an ATM system. My question: How could I do those?? AFAIK I have to edit the ~./bashrc. But the... (1 Reply)
Discussion started by: franzramadhan
1 Replies

6. UNIX for Dummies Questions & Answers

Shell Script to prompt customer for name etc

reposting How do I create a shell script called 'custinfo' to prompt a customer to enter and display back the following: name, age, address, phone number, product, price range. Thanks (1 Reply)
Discussion started by: SQLScript
1 Replies

7. Shell Programming and Scripting

Shell Script to prompt customer for name etc

How do I create a shell script called 'custinfo' to prompt a customer to enter and display back the following: name, age, address, phone number, product, price range. Thanks (1 Reply)
Discussion started by: SQLScript
1 Replies

8. Shell Programming and Scripting

Script that waits until a call is done

Hi all, I have a script that checks for the existence of files in a directory. Problem is, if a file suddenly appears, I need to move it to another directory and then call another program that does not import routines (within our DBMS). Now, this script is ever running and uses the sleep... (3 Replies)
Discussion started by: gseyforth
3 Replies

9. Shell Programming and Scripting

crontab and shell script that executes a sql.

Problem: I have a crontab and when it kicks off, xxx.sh shell script is called. Which has a nohup sqlplus session call. Problem is sql does not get executed and a text file is not getting created. Only a empty log file is getting created. Are there any constraints for crontab to open a sql... (6 Replies)
Discussion started by: radhika
6 Replies

10. Shell Programming and Scripting

script to change shell and prompt

I want to write a shell script which will change the current shell (say from csh to bsh) and my Prompt (say my name) as desired.pls help (1 Reply)
Discussion started by: SHYAM
1 Replies
Login or Register to Ask a Question

Featured Tech Videos