How to Abort or Come out of ksh script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Abort or Come out of ksh script?
# 1  
Old 06-21-2013
How to Abort or Come out of ksh script?

Hi All,

I have a requirement where if Source Count is not equal to Target count, then I need to exit/abort the script and come out. Then send an email to thummi@email.com saying "RECORD COUNT DOES NOT MATCH. Please need your help.

Here is what I have written : If even the count is not matching, it is displyaing the echo message, but not ABORTING the script.

Code:
if [ $Tgt_count == $Source_Count ];
then
    echo "Source Record Count is EQUAL to Target Record Count"
exit 0
else
    echo "Source Record Count is NOT EQUAL to Target Record Count"
   exit 7
fi

Thanks,
Thummi

Last edited by Scrutinizer; 06-22-2013 at 06:21 AM.. Reason: code tags
# 2  
Old 06-22-2013
Your variables are numbers.

Code:
if [ $Tgt_count -eq $Source_Count ] ; then
    echo "Source Record Count is EQUAL to Target Record Count"
    exit 0
else
    echo "Source Record Count is NOT EQUAL to Target Record Count"
    echo "Source Record Count is NOT EQUAL to Target Record Count" | 
      /usr/bin/mailx -s 'Failure count not equal' thummi@email.com
    exit 7
fi

The second block of echo code is redundant as I wrote it - you can improve it with tee once your code is working.
This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Abort the execution if one script have errors

Gents, I have a script which will run others scripts . Example #!/bin/bash script1 script2 script3 script4 I would like to stop all process if any of the script got errors?. If for example script1 works fine will continue script2, then if the script2 got errors, The bash should... (2 Replies)
Discussion started by: jiam912
2 Replies

2. Shell Programming and Scripting

Awk. Abort script if condition was met.

I want to abort script if input variable matched first field in any line of a file. #!/bin/sh read INPUTVAR1 awk "{if(\$INPUTVAR1 == $1) x = 1} END {if(x==1) print \"I want to abort script here\"; else print \"OK\"}" /etc/some.conf I tried "exit" and system("exit") but no luck. (1 Reply)
Discussion started by: urello
1 Replies

3. Shell Programming and Scripting

Shell Script to Abort if file name has space.

Hi, In my shell script I use the following code to copy files from one directory to other. for file in `ls`; do #----------------- Copy Files From INDIR to OUTDIR -------------# echoen "Copying File ${INDIR}/$file to ${OUTDIR}/${file}" cp ${INDIR}/$file ... (4 Replies)
Discussion started by: pinnacle
4 Replies

4. Solaris

Abort the shell script if any hive sql query gets failed

Below is my shell script from which I am trying to invoke few Hive SQL queries and the below shell script works fine. Problem Statement:- If you see my first `hive -e` block in the below shell script which contains a very long Hive SQL query. Sometimes that Hive SQL query gets failed due to... (1 Reply)
Discussion started by: raihan26
1 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. UNIX for Advanced & Expert Users

sort command abort with error

Hello, I am having an application which has been ported from UNIX. I am facing a problem with sort command. It aborts with following error message when running in a Japanese locale. sort command aborts with message "A line of the input file contains more than 20480 characters." This... (0 Replies)
Discussion started by: joshi123
0 Replies

7. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

8. Shell Programming and Scripting

How to make bash script abort?

I have a little bash script that includes make to compile with g++ and then a statement to actually run the compiled program. When it (the script) gets a syntax error, it does not abort and continues to run the previous version of the program. How can I make the script abort when g++ generates a... (1 Reply)
Discussion started by: siegfried
1 Replies

9. Filesystems, Disks and Memory

Abort core dumped!!!!

HI All, I am working on Solaris 8, i have this application runing on one of the partitions,(the installation was done here ie /export/home) And the out put of this goes to another parition of other disk attached to the same machine. After a certain period of time is get this error stating... (2 Replies)
Discussion started by: zing
2 Replies
Login or Register to Ask a Question