Script returning an error message on exiting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script returning an error message on exiting
# 1  
Old 11-15-2011
Bug Script returning an error message on exiting

Hi,

I am writing a script in which I am using an IF-Else statement.

Code sample:

Code:
 
# Check for the product.
  If (test "$3" = "Pet") Then
     Product_Code="PI"
  elif (test "$3" = "Breakdown") Then
     Product_Code="RI"
  elif (test "$3" = "Travel") Then
     Product_Code="TI"
  elif (test "$3" = "Dental & Health") Then
     Product_Code="DI"
  elif (test "$3" = "FRIENDS PROVIDENT LIFE") Then
     Product_Code="LI"
  elif (test "$3" = "LIFE 2") Then
     Product_Code="OF"
  elif (test "$3" = "Aviva Life") Then
     Product_Code="LI"
  elif (test "$3" = "Direct Line Life") Then
     Product_Code="LI"
  echo 'Not a valid Product'
  exit 1;
  fi

Please correct me if anything is wrong. Now I want to exit out if I don't have any matching condition and print the message 'Not a valid Product'
on the prompt.
I have more statements to follow if any of the condition matches.

Please suggest me.


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 11-15-2011 at 05:49 AM.. Reason: code tags, see PM
# 2  
Old 11-15-2011
You might want to do this with case/esac. That's more tidy and less to write.
# 3  
Old 11-15-2011
there is a mistake in the code
Code:
elif (test "$3" = "Direct Line Life") Then
     Product_Code="LI"
else
  echo 'Not a valid Product'
  exit 1;
fi

and try to implement case rather than else-if...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script error message

I have this UNIX script code with a query to export sql table in Oracle and export to csv file. The code gets the data correctly. However, when I run the script second time, I got the error message "not spooling currently" and shows the older data in csv file. When I delete the csv file and run... (5 Replies)
Discussion started by: Hope
5 Replies

2. UNIX for Beginners Questions & Answers

UNIX script error message

Greeting!! I wrote the below script to e-mail me only file names in a specific directory when a file is delayed for some time in a that directory. I am getting unexpected eof error message. I don't want any email if the folder is blank.(if the condition is not met) I am not getting the email at... (4 Replies)
Discussion started by: Hope
4 Replies

3. Shell Programming and Scripting

Statement returning error only launching the sh script via crontab

hi all, I created a sh script to import some tables from mysql to hive. No problem launching it manually, but if I schedule via crontab it returns me an error in the following part: #create an array containing all the tables for $dbname query="SELECT table_name FROM information_schema.tables'... (10 Replies)
Discussion started by: mfran2002
10 Replies

4. Shell Programming and Scripting

Ssh from a ksh returning not found message

Script name is test.ksh I know that that the ssh command is working properly, this can be verified by the value returned in respond variable. It is unique to the remote server _____________________________________________________ respond=$(ssh $remoteHost find... (3 Replies)
Discussion started by: Adagio
3 Replies

5. Red Hat

Postfix keeps returning "Command time limit exceeded" message

We are having issues with our Postfix. The POP and IMAP services randomly stops working an sent e-mails return a "Command time limit exceeded". We've found out that running these command fix the problem: service cyrus-imapd stop rm /var/lib/imap/tls_sessions.db* rm... (2 Replies)
Discussion started by: GustavoAlvarado
2 Replies

6. Shell Programming and Scripting

Child exiting and not returning to parent script

I am having a parent scripts which reads a file with child scripts name. I need to read one by one child script , execute it and 1. If child script fails send mail to the team with the log file 2. If the child script executes fine then proceed with the next child script execution. #!... (3 Replies)
Discussion started by: nw2unx123
3 Replies

7. Shell Programming and Scripting

error in shell script while returning values-- urgent issue plz help.

Hi, I have initailized a varaible EBID as typeset Long EBID=0 i am calculating value of EBID using certian formula as below: (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE )) return $CURR_EBID The output is as below: + (( CURR_EBID=... (6 Replies)
Discussion started by: kasanur
6 Replies

8. Shell Programming and Scripting

shell script returning error code 2 from AIX to Mainframe

Hi, I have a shell script which is residing on AIX which is triggered by Mainframe through Connect Direct. The shell script creates several files and sends those files to mainframe using Connect Direct. The shell script is working fine, still it is returning exit code 2 to mainframe. What... (0 Replies)
Discussion started by: Yogesh Aggarwal
0 Replies

9. Shell Programming and Scripting

Self referencing script error message

Hello again all. I have a user editable script that I'd like to have point out the user error to. Problem is I'm having troubles getting an echoed error message to give me the line. Here's what I'm trying to do. grep -n $loc /this/script.sh where '$loc' is the argument passed to the script.... (9 Replies)
Discussion started by: DC Slick
9 Replies

10. Shell Programming and Scripting

Exiting from script when error occurs

Hi Friends, Is it possible to exit nicely(ie, to echo a message with the error occurred) from a shell script(quiet a big one :)) once it encounter an error in between the lines? For example, in my script I am calling the command mkdir and sometimes (when the directory already exists) it... (4 Replies)
Discussion started by: Sreejith_VK
4 Replies
Login or Register to Ask a Question