The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
run shell script from oracle store procedure arnabb4u Shell Programming and Scripting 8 08-16-2006 12:16 PM
Capture Oracle return code in shell script Vikas Sood Shell Programming and Scripting 1 05-22-2006 05:32 PM
how to return an array of elements from oracle to shell script satyakiran Shell Programming and Scripting 3 08-02-2005 09:57 AM
updating a column in oracle table using shell script sveera Shell Programming and Scripting 3 05-09-2005 01:01 PM
update a oracle table using shell script ann_124 Shell Programming and Scripting 2 12-18-2004 07:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 05-04-2005
sveera sveera is offline
Registered User
  
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Red face Store return code of shell script in oracle table

Hi friends,
I have to do the following things :
1) there should be a shell script returning the returning the return code of the script. and i have to add some more details like on which machine is has run , at what time and other details and then using plsql i have to add a row to Oracle table.

2) then i have to write another script which will monitor the table for the machine_name and gets the job status of the earlier shell script .and depending on the success(0) or failure(1) (which are the status codes) a mail has to be sent to the respective groups.

Do i have to use SQLLOADER or is there any other way ?
how to i input the return code of the shell script into the table ?
Please help
thanks in advance
Veera
  #2 (permalink)  
Old 05-04-2005
sveera sveera is offline
Registered User
  
 

Join Date: Mar 2005
Location: INDIA
Posts: 60
Red face shell script return code

Hi friends,
I am able to insert the return code of some unix job into the database with storing the return code into some variable and then using that value in the insert statement.
But now i have to write a trigger which will be fired when ever there is an update or insert of the table.
Then based on the value in the status_code( return code of the script) , the trigger has to send a mail to soem group.

Please help
thanks in advance
Veera
  #3 (permalink)  
Old 05-04-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
You might be better off at the Oracle-related forum.
  #4 (permalink)  
Old 05-04-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by sveera
Do i have to use SQLLOADER or is there any other way ?
how to i input the return code of the shell script into the table ?
Veera
Answer: no, sqlldr is not necessary and more clumsy than the following method:

Script 1:
Code:
#! /bin/ksh
...
myscript # Call your script
RC=$? # Get your script's return status
HOST=$(uname -n)
# Call SQL*Plus
sqlplus username/password <<EOF
BEGIN
    INSERT INTO status_table VALUES('${HOST}', '${RC}');
    COMMIT;
END;
/
EOF

or
sqlplus username/password <<EOF
BEGIN
    your_plsql_sp('${HOST}', '${RC}');
END;
/
EOF
Scrpt 2 that monitors the status table:
Code:
#! /bin/ksh
...
# Loop forever
while :
do
    {
        sqlplus -S username/password <<EOF
set heading off feedback off serveroutput on
DECLARE
    STATUS_CODE VARCHAR2(50) := 'none';
BEGIN
    -- Attempt to find the status for the specified host
    SELECT 'StatusCode:' || 0
    INTO    STATUS_CODE
    FROM   status_table
    WHERE  hostname = '${HOST}';

    -- Found it, print the status and drop out of PL/SQL block
    DBMS_OUTPUT.PUT_LINE (STATUS_CODE);

EXCEPTION
    -- No status yet, drop out with a -1 code
    WHEN NO_DATA_FOUND THEN
        SELECT 'StatusCode:-1'
        INTO   STATUS_CODE
        FROM   dual;

        DBMS_OUTPUT.PUT_LINE (STATUS_CODE);
END;
/
EOF
    } | while read LINE # Find out what SQL*Plus says
    do
        # Look for the status message
        if print $LINE | /usr/xpg4/bin/grep -iq StatusCode
        then
            # Parse out the actual status code and break from inner loop
            STATUS_CODE=$(print $LINE | awk -F: '{print $2}')
            break
        fi
    done

    # If status code is not -1, break out of endless loop
    if [ ${STATUS_CODE:=-1} -ge 0 ]
    then
        break
    fi
    # Otherwise, continue monitoring the status table
    print "Still waiting for status..."
    sleep 5
done

if [ ${STATUS_CODE} -eq 0 ]
then
    maix -s Success...
else
    maix -s Sorry, it failed...
fi
This is one way of accomplishing your task.

If you really want to use a trigger then you are going to have to utilize UTL_SMTP.

Thomas

Last edited by tmarikle; 05-04-2005 at 01:38 PM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0