Kornshell gathering user input question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Kornshell gathering user input question
# 1  
Old 02-16-2011
Kornshell gathering user input question

Alright I have a function that does a bunch of commands and then I ask the user for what type of node they are on. So determining which node they are on means they will run a different function. Whats the correct syntax for that?
Code:
function everything
	{
         echo "do stuff"
         }
echo "What type of node are you on?"
echo "Type db for Database. Type app for Application. Type both for both."
print -n "Node: ";read var

if [ $var = both ] ; then
everything
fi

Whats wrong with that?

Last edited by Blogger11; 02-16-2011 at 03:28 PM..
# 2  
Old 02-16-2011
Code:
everything(){
echo "do stuff"
}

echo "What type of node are you on?"
echo "Type db for Database. Type app for Application. Type both for both."
print -n "Node: ";read var

case $var in
db)
echo "do db stuff"
;;
app)
echo "do app stuff"
;;
both)
everything
;;
*) 
echo "Wrong argument, bye bye ..."
exit 1
;;
esac

also have a look at the getopts
note that the keyword function should also works (also have a look at the typeset -f )

Last edited by ctsgnb; 02-16-2011 at 03:22 PM..
# 3  
Old 02-16-2011
That's not working either...
Here's just a portion of my code.
Code:
everything(){
		
		while read line; do
			temp=`perl -e '$_=shift; /^([^#]\w+) ?= ?(\w+)/; print "$1\t$2\n"' "$line"`
 			 parameter=`echo $temp | awk '{print $1}'`
 			 case "$parameter" in
	"break_poll_skip") value=`echo $temp | awk '{print $2}'`
            			   if [ $value != 1024 ]; then
           			      echo "break_poll_skip is currently not set to its recommended value of: 1024"
          			     fi;;
	"TCP.NODELAY") value=`echo $temp | awk '{print $2}'`
      	         if [ $value != yes ]; then
                 echo "TCP.NODELAY is currently not set to its recommended value of: yes"
               fi;;
	"bequeath_detach") value=`echo $temp | awk '{print $2}'`
               if [ $value != yes ]; then
                 echo "bequeath_detach is currently not set to its recommended value of: yes"
               fi;;
	NAMES.DEFAULT_DOMAIN) value=`echo $temp | awk '{print $2}'`
               if [ $value != world ]; then
                 echo "NAMES.DEFAULT_DOMAIN is currently not set to its recommended value of: world"
               fi;;
  esac
done < $ORACLE_HOME/network/admin/sqlnet.ora
}

echo "What type of node are you on?"
echo "Type db for Database. Type app for Application. Type both for both."
print -n "Node: ";read var

case $var in
both)
echo "do everything"
everything
;;
app)
echo "do app stuff"
;;
db)
echo "do db stuff"
;;
esac

---------- Post updated at 01:21 PM ---------- Previous update was at 01:20 PM ----------

It's not running this part:
Code:
while read line; do
temp=`perl -e '$_=shift; /^([^#]\w+) ?= ?(\w+)/; print "$1\t$2\n"' "$line"`
parameter=`echo $temp | awk '{print $1}'`
case "$parameter" in
"break_poll_skip") value=`echo $temp | awk '{print $2}'`
if [ $value != 1024 ]; then
echo "break_poll_skip is currently not set to its recommended value of: 1024"
fi;;
"TCP.NODELAY") value=`echo $temp | awk '{print $2}'`
if [ $value != yes ]; then
echo "TCP.NODELAY is currently not set to its recommended value of: yes"
fi;;
"bequeath_detach") value=`echo $temp | awk '{print $2}'`
if [ $value != yes ]; then
echo "bequeath_detach is currently not set to its recommended value of: yes"
fi;;
NAMES.DEFAULT_DOMAIN) value=`echo $temp | awk '{print $2}'`
if [ $value != world ]; then
echo "NAMES.DEFAULT_DOMAIN is currently not set to its recommended value of: world"
fi;;
esac
done < $ORACLE_HOME/network/admin/sqlnet.ora

and I know that works because i've tested it separately from the function.

Last edited by Blogger11; 02-16-2011 at 03:27 PM..
# 4  
Old 02-16-2011
have you setup your $ORACLE_HOME correctly ?
add
Code:
echo "ORAHOME=$ORACLE_HOME"
ls -l $ORACLE_HOME/network/admin/sqlnet.ora
cat $ORACLE_HOME/network/admin/sqlnet.ora

at the beginning of your function and run your script again.

Also check how entries are in your sqlnet.ora: are they like :

Code:
TCP.NODELAY=YES

or
Code:
TCP.NODELAY = YES

the space matter !!! ... your awk '{print$2}' result will depend on it (maybe should use the awk -F= '{print$2}')

also your should make your parameter name scanning case insensitive (use tolower() or toupper() awk functions)

Last edited by ctsgnb; 02-16-2011 at 03:36 PM..
# 5  
Old 02-16-2011
I know for a fact its not that part of the script. It has something to do with the function is not correct. I did however try what you just said and it still didn't work.

The output i get from this is.....

What type of node are you on?
Type db for Database. Type app for Application. Type both for both.
Node: <both is what i'm typing>

$

its just giving me a space after and not doing anything i have in the function.

---------- Post updated at 01:36 PM ---------- Previous update was at 01:32 PM ----------

Here is the full code:

Code:
#! /usr/bin/ksh
echo "ORAHOME=$ORACLE_HOME"
ls -l $ORACLE_HOME/network/admin/sqlnet.ora
function everything(){
		
	while read line; do
		temp=`perl -e '$_=shift; /^([^#]\w+) ?= ?(\w+)/; print "$1\t$2\n"' "$line"`
 		parameter=`echo $temp | awk '{print $1}'`
 		case "$parameter" in
	"break_poll_skip") value=`echo $temp | awk '{print $2}'`
            			   if [ $value != 1024 ]; then
           			      echo "break_poll_skip is currently not set to its recommended value of: 1024"
          			     fi;;
	"TCP.NODELAY") value=`echo $temp | awk '{print $2}'`
      	         if [ $value != yes ]; then
                 echo "TCP.NODELAY is currently not set to its recommended value of: yes"
               fi;;
	"bequeath_detach") value=`echo $temp | awk '{print $2}'`
               if [ $value != yes ]; then
                 echo "bequeath_detach is currently not set to its recommended value of: yes"
               fi;;
	NAMES.DEFAULT_DOMAIN) value=`echo $temp | awk '{print $2}'`
               if [ $value != world ]; then
                 echo "NAMES.DEFAULT_DOMAIN is currently not set to its recommended value of: world"
               fi;;
  esac
done < $ORACLE_HOME/network/admin/sqlnet.ora

#echo "Running Tunable_Settings"
./tunable_settings.ksh > tunableresults.txt
while read line 
do 
        echo $line | egrep "^value" | grep -v "would not be modified" 
done < tunableresults.txt

cd $cer_mgr
grep "MQ_CHANNEL_SUPPRESS_INTERVAL \"864000,0\"" mq_$(hostname)_${environment}_startup.ksh
if [ $? > 0 ]; then echo "MQ_CHANNEL_SUPPRESS_INTERVAL is missing or incorrect"; fi
grep "MQ_CHANNEL_SUPPRESS_MSGS \"9208,9209\"" mq_$(hostname)_${environment}_startup.ksh
if [ $? > 0 ]; then echo "MQ_CHANNEL_SUPPRESS_MSGS is missing or incorrect"; fi

while read line; do
  parameter=`echo $line | awk '{print $1}'`
  case $parameter in
	dml_locks) value=`echo $line | awk '{print $2}'`
               if [ $value != 2000 ]; then
                 echo "dml_locks is currently not set to its recommended value of: 2000"
               fi;;
	db_file_multiblock_read_count) value=`echo $line | awk '{print $2}'`
               if [ $value != 16 ]; then
                 echo "db_file_multiblock_read_count is currently not set to its recommended value of: 16"
               fi;;
	java_pool_size) value=`echo $line | awk '{print $2}'`
               if [ $value != 0 ]; then
                 echo "java_pool_size is currently not set to its recommended value of: 0"
               fi;;
	job_queue_processes) value=`echo $line | awk '{print $2}'`
               if [ $value != 5 ]; then
                 echo "job_queue_processes is currently not set to its recommended value of: 5"
               fi;;
	log_checkpoint_interval) value=`echo $line | awk '{print $2}'`
               if [ $value != 0 ]; then
                 echo "log_checkpoint_interval is currently not set to its recommended value of: 0"
               fi;;
	max_commit_propagation_delay) value=`echo $line | awk '{print $2}'`
               if [ $value != 0 ]; then
                 echo "max_commit_propagation_delay is currently not set to its recommended value of: 0"
               fi;;
	open_cursors) value=`echo $line | awk '{print $2}'`
               if [ $value != 2000 ]; then
                 echo "open_cursors is currently not set to its recommended value of: 2000"
               fi;;
	processes) value=`echo $line | awk '{print $2}'`
               if [ $value != 1500 ]; then
                 echo "processes is currently not set to its recommended value of: 1500"
               fi;;
	session_cached_cursors) value=`echo $line | awk '{print $2}'`
               if [ $value != 50 ]; then
                 echo "session_cached_cursors is currently not set to its recommended value of: 50"
               fi;;
	_kghdsidx_count) value=`echo $line | awk '{print $2}'`
               if [ $value != 1 ]; then
                 echo "_kghdsidx_count is currently not set to its recommended value of: 1"
               fi;;
	hpux_sched_noage) value=`echo $line | awk '{print $2}'`
               if [ $value != 178 ]; then
                 echo "hpux_sched_noage is currently not set to its recommended value of: 178"
               fi;;
	o7_dictionary_accessibility) value=`echo $line | awk '{print $2}'`
               if [ $value != True ]; then
                 echo "o7_dictionary_accessibility is currently not set to its recommended value of: True"
               fi;;
	cursor_space_for_time) value=`echo $line | awk '{print $2}'`
               if [ $value != False ]; then
                 echo "cursor_space_for_time is currently not set to its recommended value of: True"
               fi;;
	global_names) value=`echo $line | awk '{print $2}'`
               if [ $value != False ]; then
                 echo "global_names is currently not set to its recommended value of: False"
               fi;;
	enqueue_resources) value=`echo $line | awk '{print $2}'`
               if [ $value != 5000 ]; then
                 echo "enqueue_resources is currently not set to its recommended value of: 5000"
               fi;;
  esac
done < $CCLUSERDIR/asos.dat

touch /AuditScriptResultsnetwork.txt
#Find the NIC Speed
#wipe out the file
> /AuditScriptResultsnetwork.txt
i=0 
while [[ $i -le 6 ]] 
do 
         lanadmin -ax $i 2>/dev/null >> /AuditScriptResultsnetwork.txt
        ((i=i+1)) 
done
while read line 
do 
#echo $line | egrep -i '(speed)'
if [ `echo $line | grep '1000'` ]; then
isgig="true"
fi
if [ `echo $line | grep -i 'off'` ]; then
		if [ $isgig = "true" ]; then
		echo "Check NIC Speed settings. Speed = 1000 where Autonegotion should be on"
		fi
fi
done < /AuditScriptResultsnetwork.txt
	}

echo "Server Audit Script"
echo "Before you start you must do the following..."
echo "Go into CCL"
echo "select name,value from v$paramter order by name go"
echo "print as asos"
echo "run dm2_sys_hlth_chk_menu go"
echo "type 1 for Cerner Millennium Confiuration"
echo "Enter your Cerner Millennium username and password then type C to continue."
echo "print as shch"
print -n "Type Y when you have completed the task: ";print ""
echo "What type of node are you on?"
echo "Type db for Database. Type app for Application. Type both for both."
print -n "Node: ";read var

case $var in
both)
echo "do everything"
everything
;;
app)
echo "do app stuff"
;;
db)
echo "do db stuff"
;;
esac

I know each of those separate pieces work that are inside the function I've already tested them and it does what I want. It's this function that isn't working i dont know why.
# 6  
Old 02-16-2011
Code:
function everything(){

is wrong, you should use parenthesis OR the keyword function , not both
Korn shell :
Code:
function whatever{

}

or POSIX:
Code:
whatever(){

}

Kornshell is posix compliant so kornshell knows how to deal with posix notation.

Also, instead of
Code:
print -n "Node: ";read var

try :
Code:
 echo "Node: "; read var

You should set up a configuration file for your script : the config file would hold the parameter name as well as the threshold value then you would just scan you config file and call a function that would check the current value of your parameters against the threashold values this would be better than such a heavy case statement

Last edited by ctsgnb; 02-16-2011 at 04:16 PM..
This User Gave Thanks to ctsgnb For This Post:
# 7  
Old 02-16-2011
Quote:
Originally Posted by ctsgnb
Also, instead of
Code:
print -n "Node: ";read var

try :
Code:
 echo "Node: "; read var

print is non-standard and there are too many implementations of echo for it to be predictable. A lot of people will say that one should use:
Code:
printf "Node: "

.

Blogger11: I think the problem is with the perl invocation at the start of the function. If I try it in a terminal I get nothing. I can't find ?= in the perlre man page, although I can find ?() and (?=...).

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

2 Loops gathering input

Greetings all, I have came up with some code, to read an input file and generate a list, here is a sample of what I am working with. The variable $USER will be inputted by the person running the utility. do folder=${line%} echo "$folder $USER done < list.txt sample of list.txt- ... (15 Replies)
Discussion started by: jeffs42885
15 Replies

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

3. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

4. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

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

6. UNIX for Advanced & Expert Users

Gathering data using SAR

Hi everyone, I would like to ask if it is possible to gather SAR data on a specified time. let say yesterdays report, i want to get data at around 12PM and 5PM. thank you. (2 Replies)
Discussion started by: cwiggler
2 Replies

7. Shell Programming and Scripting

Question about user input

Hello all, How can i have a user input that reads like this: echo -n "Please enter a & b:" 10 20 read a read b echo $a echo $b 10 20 right now i have divided it into two echos, like echo -n "a: " echo -n "b: " (1 Reply)
Discussion started by: rrahmegni
1 Replies

8. Shell Programming and Scripting

A question about the newline character in KornShell scripts

Dear all, How can we know in a KornShell script reading a value from the standard input, that the entered value is the newline character? because as far as I know we cannot use \n for pattern matching. For example: #!/bin/ksh print -n "enter your value: " read VALUE if ] then ... (2 Replies)
Discussion started by: dariyoosh
2 Replies

9. Shell Programming and Scripting

unix question: user supplied input for 'alias'

I have a program to scan the log files and I want to pipe the output to 'less'. I want to create an alias such that following are equivalent scanlog chunky.lst = /udd/n2man/utils/scanlog chunky.lst|less where chunky is user supplied file which can change. Is this possible as an alias or... (1 Reply)
Discussion started by: ospreyeagle
1 Replies

10. Shell Programming and Scripting

Gathering info on one line

Hi all again, here is the file i am working on : GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04 GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06 GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11 GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18... (5 Replies)
Discussion started by: HowardIsHigh
5 Replies
Login or Register to Ask a Question