Visit Our UNIX and Linux User Community


Error to Read Input from command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error to Read Input from command line
# 1  
Old 07-01-2014
Error to Read Input from command line

Team ,
I am trying to write a case condition for database backups.But I am unable to make the script to read input from command line .
Code:
 
 
while true ;do
 read -p "Do You Wish To Take Database Backup ?? " yn
  case $yn in
 [Yy]*) echo " YES take backup ";;
        [Nn]*) echo " NO BACKUP " ;;
         *) echo "Please Answer Yes OR NO " ;;
esac
done

I am getting below error after executing .


Code:
 
read: 0403-039 No query process for pipe.

Why this error pop up ?
# 2  
Old 07-01-2014
You are probably executing it with the wrong shell. Are you using ksh93 ? In ksh93 -p is used to read output from a coprocess, whereas bash uses the -p option for a prompt.
# 3  
Old 07-01-2014
Code:
echo $SHELL

should give you then name of your shell.
# 4  
Old 07-01-2014
What shell are you in? For me, I'm usually Korn shell, ksh so I would craft is like this:-
Code:
while true ;do
 read yn?"Do You Wish To Take Database Backup ?? "
 case $yn in
   [Yy]*) echo " YES take backup "        ;;
   [Nn]*) echo " NO BACKUP "              ;;
       *) echo "Please Answer Yes OR NO " ;;
 esac
done

I hope that this helps,


Robin
# 5  
Old 07-01-2014
Thanks for your replies this is ksh .Batte I used your sytax .


Code:
 
while true ;do
        
read  yn? "Do You Wish To Take Database Backup for $DB?? " 
 case $yn in
 [Yy]*) echo " YES take backup ";;
        [Nn]*) echo " NO BACKUP " ;;
         *) echo "Please Answer Yes OR NO " ;;
esac
done

I don't see its running fine .I can see more errors though its taking inputs from command line .May be i should add break in each choice to come out of the loop ?


Code:
 
./Config.sh[56]: Do You Wish To Take Database Backup for ?? : This is not an identifier.
Please Answer Yes OR NO
y
./Config.sh[56]: Do You Wish To Take Database Backup ?? : This is not an identifier.
 YES take backup
./Config.sh[56]: Do You Wish To Take Database Backup ??  : This is not an identifier.
Please Answer Yes OR NO
n
./Config.sh[56]: Do You Wish To Take Database Backup ??   : This is not an identifier.
 NO BACKUP
./Config.sh[56]: Do You Wish To Take Database Backup ??  : This is not an identifier.
Please Answer Yes OR NO
cancel
./Config.sh[56]: Do You Wish To Take Database Backup for ?? : This is not an identifier.
Please Answer Yes OR NO

# 6  
Old 07-01-2014
You have a space in your read command between the yn? and the quoted prompt. Take this out. I get the following output to the code as posted:-
Code:
Do You Wish To Take Database Backup ?? y
 YES take backup 
Do You Wish To Take Database Backup ?? n
 NO BACKUP 
Do You Wish To Take Database Backup ?? rubbish 
Please Answer Yes OR NO 
Do You Wish To Take Database Backup ??

... and then I cancelled with Cntl-C

Perhaps also use double quotes in the case statement like this to cater for someone just pressing ENTER:-
Code:
case "$yn" in



Robin
# 7  
Old 07-01-2014
Just trying to add the case condition to a for loop where for have n number iterations.but after giving choice as N its completly coming out of for loop
not iterating for other DB values in for loop .am i missing something ? Before adding CASE conditition for loop was iterating for n number values


Code:
 
for DB in ${DATABASES}
do
 doing some thing for n number of dbs... 
while true ;do        
read yn?"Do You Wish To Take Database Backup for $DB?? " 
 case "$yn" in
 [Yy]*) echo " YES take backup ";
        break ;;
        [Nn]*) exit;;
         *)    echo "Please Answer Yes OR NO " ;;
esac
done
done

Out is below

Code:
 
Do You Wish To Take Database Backup for ? n


Last edited by rocking77; 07-01-2014 at 09:58 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #850
Difficulty: Medium
Every Bluetooth device has a unique 48-bit address.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Input for read command

Hello, I want to use the read command in order to input a keyword from the keyboard. I then want to use this keyword in a grep command. How to I input a phrase as a keyword? For example if I use read keyword "today is" and then use grep, I get "No such file or directory" error. (6 Replies)
Discussion started by: FelipeAd
6 Replies

2. Shell Programming and Scripting

Script to read command line input and change it to some form

Hi, I want to write a small code in which script changes command line input to some form. Example script.sh a1 a2 a3 a4 ..... output should be "a1|a2|a3|....." Number of inputs in command line can be any variable (2 Replies)
Discussion started by: Raza Ali
2 Replies

3. Shell Programming and Scripting

Read input file with in awk script not through command line

Hi All, Do we know how to read input file within awk script and send output toanother log file. All this needs to be in awk script, not in command line. I am running this awk through crontab. Cat my.awk #!/bin/awk -f function test(var){ some code} { } END { print"test code" } (5 Replies)
Discussion started by: random_thoughts
5 Replies

4. Shell Programming and Scripting

Print output and read input on same line

How do I print output and read input on the same line in ksh? echo Hello, what is your name? read name (1 Reply)
Discussion started by: robin_simple
1 Replies

5. Shell Programming and Scripting

Read input while executing the command

Hi everyone, i have made a very simple script where it reads the user input and converts the number from celcius to faranheit but instead of running the command and prompting the user for input I want to be able to simply enter a number at the end of the command to run the script. ex. instead of... (1 Reply)
Discussion started by: subway69
1 Replies

6. Shell Programming and Scripting

filtering input from read command

I need help understanding a script I'm modifying which someone else has written. Basically I’m looping through a buffer that holds records fetched from a database query. I need a way to separate the primary key values from other attributes in the result. Heres the code: BUFF=buffer_file >... (5 Replies)
Discussion started by: d3mon_spawn
5 Replies

7. Shell Programming and Scripting

sed to read line by line and input into another file

I have two files. Fileone contains text string one text string two text string three Filetwo contains Name: Address: Summary: Name: Address: Summary: Name: Address: Summary: I would like to use sed to read each line of file one and put it at the end of the summary line of file... (3 Replies)
Discussion started by: dolacap
3 Replies

8. UNIX for Dummies Questions & Answers

How to read a line of text from user input?

Hiii I wanna a read a line of text from standard input. The user enter data like this way name phone_no month1_salary month2_salary that is user enter the name ,phone no and salary of 2 months in a single line by giving spaces. I wanna add the 3rd and 4th fields ...ie add both... (4 Replies)
Discussion started by: krishnampkkm
4 Replies

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

10. Shell Programming and Scripting

read a file as input and pass each line to another script

Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names. My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)
Discussion started by: sajjad02
0 Replies

Featured Tech Videos