Command to accept input


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command to accept input
# 1  
Old 02-07-2008
Command to accept input

I am trying to write a one line command for Oracle grid control. I am using a semi-colon to separate the commands. But, I am having a problem with a shell script accepting input. Wondering if you can help.

Here is what I am trying to do:

(PGPRD5432)@prd01:/> cd /export/home/postgres ## home directory, currently work on (PGPRD5432)
(PGPRD5432)@prd01:~> source .bash_profile## script that allows me to choose environment variables

Multiple Postgres Clusters, Please Select One
(PG: Env Name: Port: Version)

1) PG:PRD:5432:8.1.4
2) PG:PRD:5434:8.1.4
#? 2 ##Here, I enter option 2
(PGPRD5434)@prd01:~> env | grep PG ##Now changed to (PGPRD5434)
PGENV=PRD
PGBKUP=/pgbackup/PGPRD5434
PGCLUST=PGPRD5434
PGWORK=/pgwork
PGDATA=/pgcluster/data/PGPRD5434
PGVERSION=8.1.4
(PGPRD5434)@prd01:~>

When I try a one liner, I cannot figure out how to get .bash_profile to accept the "2". Here is what I am trying with no success.

cd /export/home/postgres;. .bash_profile | 2; env | grep PG

cd /export/home/postgres;. .bash_profile; 2; env | grep PG

cd /export/home/postgres;. .bash_profile; echo "2" ; env | grep PG

cd /export/home/postgres;. .bash_profile; echo 2; env | grep PG
# 2  
Old 02-07-2008
An interactive profile is highly evil. Do you absolutely _have_ to use this thing?

If so, try using echo and pipes to send the '2' to the source command:
Code:
echo "2" | . /export/home/postgres/.bash_profile ; env | grep PG

If the above doesn't work, you might need to use 'expect' to simulate a tty for the source command to interact with.

Really, find the person responsible for this mess and give them a smack in the head. A profile that pauses and waits for input is a great way to screw up all kinds of automation processes. At least change it to check if it's running interactive or not and make an automatic choice if not.
# 3  
Old 02-07-2008
Quote:
Originally Posted by rexmabry

(PGPRD5432)@prd01:~> source .bash_profile## script that allows me to choose environment variables

Multiple Postgres Clusters, Please Select One
(PG: Env Name: Port: Version)

1) PG:PRD:5432:8.1.4
2) PG:PRD:5434:8.1.4
#? 2 ##Here, I enter option 2
(PGPRD5434)@prd01:~> env | grep PG
The .bash_profile is the script your running?

I bet that there is actually a script inside that login script that you could dissect that could do all of this cleaner. Its actually building a menu by probing the database environment and what not.
# 4  
Old 02-08-2008
Thanks for trying to help. But the echo "2" didn't work either. However, the way you cleaned it up is awesome.

We approaching it differently. The .bash_profile script gives the option to set postgres clusters (ports). Instead of trying set my port. I am going to put the port in the command. Like this:

psql -p 5432 -c "select 'port: 5432', pg_postmaster_start_time();" | grep "[0-9]-[0-9]" | sed 's/^ //'


Another issue I had was that the Oracle grid control agent seems to do an "su" to another user. We are setting the path of the agent, so when the "su" happens it will already have the path. Just an FYI
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to accept user input on the fly

I want a shell script that accepts user input simultaneously when performing other tasks. Example: A shell script should echo some messages on the console and when the user presses some keys it should respond to that action. say, when user presses the key A - more information should be printed... (2 Replies)
Discussion started by: Arun_Linux
2 Replies

2. Shell Programming and Scripting

accept input on an echo output

echo (some info) read? <&1(not working for me) (1 Reply)
Discussion started by: robin_simple
1 Replies

3. Programming

How to accept multiple lines input from User in C?

Hi I want to accept multiple lines input with spaces from User and i have a working code like this. char sRes; char sReq; printf("Please enter request:"); scanf("%",sReq); /* Accept the input from user */ printf("\nPlease enter response:"); scanf("%",sRes); but the... (4 Replies)
Discussion started by: AAKhan
4 Replies

4. UNIX for Advanced & Expert Users

Gedit semi-frozen/hangs; does not accept keyboard/mouse input

I have a very weird problem with the gedit 2.30.3 text editor on GNOME 2.30.2 (Ubuntu Linux 10.04 LTS): Any and all mouse clicks and key-presses into the gedit window are summarily ignored. When I say the gedit window, I mean the gedit window proper, the window contents, not the decoration of... (1 Reply)
Discussion started by: ropers
1 Replies

5. Shell Programming and Scripting

SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script

Dear All, The sqlplus 'Accept' command is not waiting for user input when I include the command within a shell script. Note: The 'Accept' command is working fine if I execute it in a SQLPLUS Prompt. Please fins the below sample script which i tried. SCRIPT: -------- #!... (4 Replies)
Discussion started by: little_wonder
4 Replies

6. Shell Programming and Scripting

How to accept multiple input in a same variable

Hi All, I am trying to write a script in which I need to accept multiple value in the same variable. The case Is that I have put a FOR loop and inside the FOR loop I am accepting a variable value. And I require all the values which gets inputted in the variable. To be... (5 Replies)
Discussion started by: rahulmittal87
5 Replies

7. UNIX for Dummies Questions & Answers

accept user input?

how would i accept user input from the keyboard? (2 Replies)
Discussion started by: JamieMurry
2 Replies

8. Shell Programming and Scripting

How to prompt for input & accept input in ONE line

hi, am a new learner to shell programming. i have a script which will prompt for user to key in their name & display their name afterwards. script ===== echo "Pls enter your name:" read name echo "Your name is $name." output ===== Pls enter your name: Bob Your name is Bob. what... (2 Replies)
Discussion started by: newbie168
2 Replies

9. Shell Programming and Scripting

Accept input parameters

Dear All, I got a table creation file in a standard format. I need to accept parameters from the user & then based on the input change the data in the file. For. eg. i will accept the database name, dbspace name & user name from the user and accordingly change the same in the table creation... (2 Replies)
Discussion started by: lloydnwo
2 Replies

10. Shell Programming and Scripting

Accept user input - only numbers

I have a situation where I want the user to enter only numbers in response to a READ command. I have some validation to restrict the number to be between 1 and 12, but if the user type in some characters the script echoes some error message and goes to the next command. Below is a snippet of the... (1 Reply)
Discussion started by: pvar
1 Replies
Login or Register to Ask a Question