reading yum user input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading yum user input
# 1  
Old 06-14-2011
reading yum user input

I am writing a script where it uses yum to install. I need to read the user input for yum ie "y or n". If the user types "y", the script should continue running. If the user types "n" then the whole script should be terminated.

line1
line2
yum install package
line3
line4

From above, line1 and line2 are executed and after the yum line, if the user input is "n" then dont execute the rest of the lines and terminate the script by it own..
# 2  
Old 06-14-2011
Code:
line1
line2
echo "Do you want to install (y/n)"
read answer
if [ "$answer" ne "y" ]
     exit 1
fi
yum install package
line3
line4

# 3  
Old 06-14-2011
Thank you.

But my need is that the line "yum install package" should run and according to the user input to this command, the script should run or terminate. I hope I am clear enough.
# 4  
Old 06-14-2011
Code:
if [ "$answer" ne "y" ]
     exit 1
fi

exit is used to terminate the script (if the user didnt choose "y")
# 5  
Old 06-14-2011
Sorry, I was not clear enough.

Say line1 and line2 are executed and then the line "yum install package" is executed. User needs to input "y" or "yes" to install the package and "n" or "no" to quit the yum install. If the user input "y" or "yes" the script should continue as such, ie yum will install package and after that line3 and line4 of script is executed.
Now if the user input "n" or "no" for the yum install step, the yum will not install the package and the script should be terminated and line3 and lin4 should not be executed.
# 6  
Old 06-14-2011
This should work, i don't have linux to try now, the assumption is that when user gives no to yum it returns with non-zero status. Try if this works.

Code:
line1
line2
yum install pakage
if [ $? -ne 0 ]
then
 exit 1
fi
line3
line4

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to embed data instead of reading user input from an array?

Hello, I am running under ubuntu1 14.04 and I have a script which is sending given process names to vanish so that I'd see less output when I run most popular tools like top etc in terminal window. In usual method it works. Whenever I restart the system, I have to enter the same data from... (2 Replies)
Discussion started by: baris35
2 Replies

2. UNIX for Beginners Questions & Answers

Installation of virt-manager while yum update and yum install rhvm does not work

I have downloaded RHEV-H 4.2 Red Hat Virtualization - Red Hat Customer Portal (RHVirtualization 4.2 Host and Manager iso). I uploaded the image and installed on an HP G9 server baremetal. I found I dont have a WAN/net connectivity later on HPG9 server. How can I still install virt-manager on... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

3. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

4. UNIX for Dummies Questions & Answers

User input while reading from a file

I am not able to capture the user input in this script(bash).There is prompt for user input.Could some one help me capture user input while reading afile? while read line do echo "$i" path1=$line path2=`echo $line|sed s/new_dir/old_dir/` echo "Do you want to replace?";... (4 Replies)
Discussion started by: parijat guh
4 Replies

5. Shell Programming and Scripting

Reading user input...problem with tab key

Hi all, I have a little problem with my shell script (reading user input, save user input to variable, invisible characters in the log file :() printf "1. What's your file path?" /path/to/my/file read -e FILE I have invisible characters in my log file (e.g. <ESC> or ^G) when I'm... (3 Replies)
Discussion started by: splendid
3 Replies

6. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

7. UNIX for Dummies Questions & Answers

Centos commands: Yum Upgrade versus Yum update

Hi, I would like to know the difference between YUM UPDATE and YUM UPGRADE. The man pages say upgrade is same as update with the obsolete option. And by default it says the obsolete option is turned on, which would make them equivalent. Does not say what obsolete does. Can someone please... (3 Replies)
Discussion started by: mojoman
3 Replies

8. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

9. Shell Programming and Scripting

Reading input from user

how do we read input from a user e.g i want to ask a user to enter 6 sets of numbers how do i control information from the user? i have this....... #!/bin/bash echo "Please enter six numbers" read number echo $number >> file1 but this stops after the first number..how can i... (2 Replies)
Discussion started by: vadharah
2 Replies

10. Shell Programming and Scripting

reading from input

Hi guys , As you know normally ' read ' statement waits for the user to press enter and then terminates the input ............. Can anyone of u tell me how do i read a single character from input without waiting for the user to press enter ................ Thanks, Nagesh. (1 Reply)
Discussion started by: nageshrc
1 Replies
Login or Register to Ask a Question