Read input and match string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read input and match string
# 8  
Old 11-07-2013
Quote:
Originally Posted by Don Cragun
It sounds like it is a 1988 version, but try:
Code:
what /usr/bin/ksh|grep Version

Why did the script you posted start with #!/bin/ksh if your shell is /usr/bin/ksh???
sorry that was bad on my part, i had copied part of my script from somewere else...but the below worked and you were absoletly right...it is 88

Code:
host:$ what /usr/bin/ksh|grep Version                                                                                                                                                       
        Version 11/16/88
host:$

also i tried something like below which seems to work, but i would like to know how you would do it ?
Code:
echo DB LIST
ps -ef | grep pmon | grep -v grep | awk -F_ '{print $3}' | sort > /tmp/k_out.txt 
ps -ef | grep pmon | grep -v grep | awk -F_ '{print $3}' | sort
echo

echo "Enter database name from the above list"
echo
read ORACLE_SID
while [[ $ORACLE_SID = "" ]]; do
echo reenter SID again
   read ORACLE_SID
done
echo
echo Database selected is: $ORACLE_SID
echo


#check to make sure SID pass is correct or not, if not exit
cat /tmp/k_out.txt|grep -w $ORACLE_SID
INPUT_STAT1=$?
if [ "$INPUT_STAT1" = "0" ]
then
# dO NOTHING
echo "Database name select was good"
else
echo "Database name was NOT selected from the List Provided"
fi


Last edited by Franklin52; 11-08-2013 at 02:05 PM.. Reason: Please use code tags
# 9  
Old 11-07-2013
I would probably do something more like:
Code:
#!/usr/bin/ksh

echo "DB LIST:"
ps -ef | awk -F_ '/pmon/{print $3}' | sort | tee db_list$$
trap "rm db_list$$" EXIT

printf "Enter database name from the above list: "
read ORACLE_SID
while [ "$ORACLE_SID" = "" ]
do
        printf "reenter SID: "
        read ORACLE_SID
done
printf "\nDatabase entered is: %s\n\n" "$ORACLE_SID"

#check to make sure SID pass is correct, if not exit
if grep -q "^$ORACLE_SID$" db_list$$
then
        # dO NOTHING
        echo "Database name selected was good"
else
        echo "Database name was NOT selected from the List Provided" >&2
        exit 1
fi

This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 11-07-2013
what exactly dose the below do?
Code:
trap "rm db_list$$" EXIT


Last edited by Franklin52; 11-08-2013 at 02:05 PM.. Reason: Code tags
# 11  
Old 11-07-2013
Quote:
Originally Posted by crazy_max
what exactly dose the below do?
trap "rm db_list$$" EXIT
It removes the temporary file created by this script when the script exits.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

Read input from Keyboard, do not proceed if no input

Hi, I am working on a script, which requests users to enter input. Ex: read -p "Please enter your email id:" email I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input. I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Discussion started by: aravindadla
7 Replies

3. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

6. Shell Programming and Scripting

Match string from two file input

Hello all, I have file like this: file 1: aa bb cc dd ee file2: 111 111 111 111 111 111 (2 Replies)
Discussion started by: attila
2 Replies

7. Shell Programming and Scripting

Take input from read and place it a string in another file

Hi, This is most likely a dumb question but I could not find answer to it elsewhere. I'm building a simple menu with case /esac and want to read user's input: Please enter XYZ ; read XYZ How do I take the value of XYZ and insert it as a variable $XYZ in file file.txt ? I may need to... (9 Replies)
Discussion started by: svetoslav_sj
9 Replies

8. Shell Programming and Scripting

exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
Discussion started by: bash_in_my_head
8 Replies

9. UNIX for Dummies Questions & Answers

Regex to match when input is not a certain string (can't use grep -v)

Hey everyone, Basically, all I'm looking for is a way to regex for not a certain string. The regex I'm looking to avoid matching is: D222 i.e. an equivalent of: awk '!/D222/' The problem is that I use this in the following command in a Bash script: ls ${source_directory} | awk... (1 Reply)
Discussion started by: kdelok
1 Replies

10. Programming

How i can read a long integer from standar input and a string with as many characters as specified..

how i can read a long integer from standar input and a string with as many characters as specified in the number? i thing that i must use the read command ofcourse.... (6 Replies)
Discussion started by: aintour
6 Replies
Login or Register to Ask a Question