Manual input using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manual input using script
# 1  
Old 11-30-2011
Manual input using script

hello,

I have one script A that requires to to press "q" manually to quit the script.

I am calling script A in another script B. Is there any way by which this "giving q manually" can be done inside script. and it does not require to gve it manually when using script B.

Thanks.
# 2  
Old 11-30-2011
script1.sh:
Code:
#! /bin/bash
echo "I am in script 1. Going to script 2"
./script2.sh
echo "I am back to script 1. Exiting now"

script2.sh:
Code:
#! /bin/bash
echo "I am in script2"
read -p "Press q to quit from script B: " input
if [ "$input" == 'q' ]
then
    echo "Exiting from script 2"
    exit
fi

Is this what you're looking for?
# 3  
Old 11-30-2011
Hello,

Please see below for more clarity:

1.sh
2.sh

out put of 1.sh on consol is as below

Code:
 
Please run report:
2:       dailyreport
q:       quit
Choose:

now i m calling 1.sh in 2.sh, so I want to give the option "q" automatically from script 2.sh when its asked while execution of 1.sh from 2.sh.
# 4  
Old 11-30-2011
--B.sh--
Code:
#!/bin/bash
s2='A.sh'
echo "Calling Another Script -> $s2";sleep 1
export c="$1"
. $s2

--A.sh--
Code:
#!/bin/bash
sleep 5
echo "B script is called from $$ pid"
while [ "$c" != "q" ] ; do
read -p "Please enter choice ? [ q (for quit)]" c
done

Code:
# ./B.sh
Calling Another Script -> A.sh
B script is called from 23032 pid
Please enter choice ? [ q (for quit)]a
Please enter choice ? [ q (for quit)]d
Please enter choice ? [ q (for quit)]f
Please enter choice ? [ q (for quit)]q

if you send a parameter to B.sh and export it Smilie
Code:
# ./B.sh q
Calling Another Script -> A.sh
B script is called from 23350 pid

regards
ygemici
# 5  
Old 11-30-2011
Thanks for the reply.

The problem is we do not have access of A.sh (as in your example). So it would not be possible to export the same variable name (as in B.sh) varibale corresponding to A.sh. Smilie

thats what more worrying as how would I pass "q" when its required.
# 6  
Old 11-30-2011
Quote:
Originally Posted by skhichi
Thanks for the reply.

The problem is we do not have access of A.sh (as in your example). So it would not be possible to export the same variable name (as in B.sh) varibale corresponding to A.sh. Smilie

thats what more worrying as how would I pass "q" when its required.
we must know that hold for q value which defined in "1.sh" script then maybe we define(export) to this in the "2.sh".
do you have read permission on the "1.sh" ?
# 7  
Old 11-30-2011
I hope this would help u...

Code:
cat > B.sh
#!/bin/bash
echo "Calling Another Script -> A.sh";
./A.sh < input.txt

create an input.txt file with all options (newline separated) and last option should be q.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Running a program manual vs script

Hello - I am new to unix... very new. I am running a program at the command prompt:-nohup ./ledger - comptroller_extract 05/11/2018 & The above runs as expected. If I put it in a sh script:- current_date=$(date+%m/%d%y) nohup ./ledger - comptroller_extract $current_date & This does... (4 Replies)
Discussion started by: MSpeare
4 Replies

2. Solaris

Set password in bash script without manual entry-Solaris 10

Hi I have a root script which is setting up user and his dirs and so on. After I create user and set up all the necessary I have to manually set user password. I try all possible ways what google find me and nothing works for me. If maybe one of you have a solution for my problem it will be... (1 Reply)
Discussion started by: Jaffakeks
1 Replies

3. Shell Programming and Scripting

Hundreds of files need manual preparation. Does shell script could do it automatically?

Hello friends, I have hundreds files in hand, which need extract some data from logs and read these data into an input file. Here I will explain in detail using these two files as attached. read some data from .log file and write it into the .in file. **explanation is given inside two... (9 Replies)
Discussion started by: liuzhencc
9 Replies

4. Shell Programming and Scripting

How to check if script is run via cron or manual=command line?

Hi all, I have a script that can be run via cron or via the command line. Is there any way that I can place something on the script to be able to distinguish/differentiate whether the script was run via a user in the command line or whether it was run from the cron? (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

6. Shell Programming and Scripting

giving input without manual intervention

Hi all, I am looking for a specific requirement. I am trying to create a wrapper over a set of shell scripts. Some shell scripts wait for user inputs. These inputs may not be same format. And will be spread across multiple files. In short a set of scripts are going to be run on another set... (1 Reply)
Discussion started by: krk1729
1 Replies

7. Shell Programming and Scripting

on manual script need to add logfile

hi all, 1.I am new to linux shell scripting. 2.i had an rman.sh script which will take backup all database using CATALOG DATABASE. 3.While executing that script my catalog DB gets shutdown. 4.The rman.sh script are executed manually. 5.so i need log for rman.sh .And also it is very useful... (1 Reply)
Discussion started by: jp_linux
1 Replies

8. UNIX for Dummies Questions & Answers

Manual run a script on UNIX

Hi,I'm currently working on an dev environment that has no jobs to run the scripts.How can I manual run the scripts. on Unix? ---------- Post updated at 05:45 AM ---------- Previous update was at 05:43 AM ---------- Is it something like this.... ../int/inbound>./filename.sh inputfilename ... (5 Replies)
Discussion started by: sonja
5 Replies

9. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

10. Shell Programming and Scripting

script execute by cron problem, but manual ok

Hi; I'm facing the problem with my script like below 30 0 * * * /data/SCRIPT/LOADLOGS/loadata1.sh 2 1 >> /tmp/loaddata.txt loadata1.sh calling a another 2 scripts which we need to exe in sequence. when it perform by cron jon, sometimes it just can process 20 recs or less or nothing but... (6 Replies)
Discussion started by: izai
6 Replies
Login or Register to Ask a Question