Sponsored Content
Top Forums Shell Programming and Scripting Is there a more efficient way? Post 93177 by SelectSplat on Friday 16th of December 2005 08:04:15 AM
Old 12-16-2005
The first two tips are GREAT thanks. SQL*Plus is new to me, as nearly all my experience has been with ISQL.

Your last suggestion is extremly interesting to me, as I can barely follow what's going on. In fact, I don't understand at all.

Is 'RESULTS' an array of strings being assigned the result set from sqlplus?
What is IFS?
What is /nolog ?
I'm completly lost with the 'if'.
If I use this method, will I still have each 'word' in each row in it's own variable?
Can you psudo code document it for me?

Also, I'm not exactly sure what version of korn we're using, but I did notice that VAR=$(command) doesn't work as I'd expect. It looks like I have the same funcationality with VAR=`command`, but I'm not 100% sure.

Sorry for all the questions. Thanks for you reply, and in advance for your further elaboration.


Quote:
Originally Posted by tmarikle

Personally, I prefer to use this kind of construct:
Code:
# Read whole lines
IFS='
'
set -A RESULTS $({
    sqlplus -s /nolog "
        connect un/pw
        select or exec ...;
"
    print RC=$?
} 2>&1)

if [[ "RC=0" != ${RESULST[(( ${#RESULTS[@]} - 1} ))] ]]
then
    write_log "sqlplus error"
    exit 1
fi

for i in ${RESULTS[@]}
do
    case $i in
        ORA*|SP2*|PLS*)
            write_log "sql error"
            exit 1
        ;;
        ... whatever else you want to look for ...
        ;;
    esac
done

If you results exceed 4098, you won't want to use an array if you Korn shell is KSH88. I believe that the newer Korn shells will allow more the 4098 elements.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Efficient Dispatching

Does anyone know what's new with Efficient dispatching in the Solaris 2.8 release (vs Solaris 2.6) release? Specifically, does anyone know of a good website to get detailed information on thread dispatching using efficient dispatching in solaris 2.8? Thank you. (1 Reply)
Discussion started by: uchachra
1 Replies

2. Shell Programming and Scripting

Efficient way of Awk

Hi, Can someone let me know if the below AWK can be made much simpler / efficient ? I have 200 fields, I need to substr only the last fields. So i'm printing awk -F~ 'print {$1, $2, $3....................................$196,$197 , susbstr($198,1,3999), substr($199,1,3999)..}' Is there a... (4 Replies)
Discussion started by: braindrain
4 Replies

3. Shell Programming and Scripting

Can you suggest a more efficient way for this?

Hi I have the following at the end of a service shutdown script used in part of an active-passive failover setup: ### # Shutdown all primary Network Interfaces # associated with failover ### # get interface names based on IP's # and shut them down to simulate loss of # heartbeatd ... (1 Reply)
Discussion started by: mikie
1 Replies

4. Shell Programming and Scripting

help on most efficient search

Hello, We have a directory with 15 sub-directories where each sub-directory contains 1.5 to 2 lakhs of files in it. Daily, around 300-500 files will be uploaded to each sub-directory. Now, i need to get the list of files received today in most efficient way. I tried using "find with newer... (16 Replies)
Discussion started by: prvnrk
16 Replies

5. Shell Programming and Scripting

Is there a way to make this more efficient

I have the following code. printf "Test Message Report" > report.txt while read line do msgid=$(printf "%n" "$line" | cut -c1-6000| sed -e 's///g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|') putdate=$(printf "%n" "$line" | cut -c1-6000| sed -e 's///g' -e 's|.*PutDate\(.*\)PutTime.*|\1|')... (9 Replies)
Discussion started by: gugs
9 Replies

6. Shell Programming and Scripting

efficient search

Hi, i have 2 files each with 200K lines. Each line contains a number. Now, i need to get the list of numbers existing in one fine and NOT in other file. I'm doing this by reading each number from 1 file and grepping on other file. But this taking LOT of time. Is there any efficient way of doing... (14 Replies)
Discussion started by: prvnrk
14 Replies

7. UNIX for Advanced & Expert Users

efficient repace

some of the data i receive has been typed in manually due to which there are often places where i find 8 instead of ( and the incorrect use of case what according to you is the best way to correct such data. The data has around 20,000 records. The value i want to change is in the 4th field.... (2 Replies)
Discussion started by: VGR
2 Replies

8. UNIX for Dummies Questions & Answers

Is this regex efficient?

I want to match the red portion: 9784323456787-Unknown Phrase with punctuation "Some other PhrASE." Is this the best regex to match this? '978\{10\}-*' (4 Replies)
Discussion started by: glev2005
4 Replies

9. UNIX for Advanced & Expert Users

Efficient way to grep

Hi Experts, I've been trying simple grep to search for a string in a huge number of files in a directory. grep <pattern> * this gives the search results as well as the following - grep: <filename>: Permission denied grep: <filename>: Permission denied for files which I don't have... (4 Replies)
Discussion started by: sumoka
4 Replies

10. Shell Programming and Scripting

Help with Efficient Looping

Hello guys My requirement is to read a file with parent-child relationship we need to iterate through each row to find its latest child. for eg. parent child ABC PQR PQR DEF DEF XYZ Expected Output ABC XYZ PQR XYZ DEF XYZ Script Logic : read parent from file seach child... (4 Replies)
Discussion started by: joshiamit
4 Replies
Net::SNPP::Server(3pm)					User Contributed Perl Documentation				    Net::SNPP::Server(3pm)

NAME
Net::SNPP::Server - SNPP server library DESCRIPTION
An object interface for creating SNPP servers. Almost everything you need to create your very own SNPP server is here in this module. There is a callback() method that can replace default function with your own. them. Any SNPP command can be overridden or new/custom ones can be created using custom_command(). To disable commands you just don't want to deal with, use disable_command(). SYNOPSIS
There may be a synopsis here someday ... METHODS
new() Create a Net::SNPP::Server object listening on a port. By default, it only listens on the localhost (127.0.0.1) - specify MultiHomed to listen on all addresses or LocalAddr to listen on only one. my $svr = Net::SNPP::Server->new( Port => port to listen on BindTo => interface address to bind to MultiHomed => listen on all interfaces if true (and BindTo is unset) Listen => how many simultaneous connections to handle (SOMAXCONN) # the following two options are only used by handle_client() MaxErrors => maximum number of errors before disconnecting client Timeout => timeout while waiting for data (uses SIGARLM) ); client() Calls accept() for you and returns a client handle. This method will block if there is no waiting client. The handle returned is a subclass of IO::Handle, so all IO::Handle methods should work. my $client = $server->client(); ip() Return the IP address associated with a client handle. printf "connection from %s", $client->ip(); socket() Returns the raw socket handle. This mainly exists for use with select() or IO::Select. my $select = IO::Select->new(); $select->add( $server->socket() ); connected() For use with a client handle. True if server socket is still alive. shutdown() Shuts down the server socket. $server->shutdown(2); callback() Insert a callback into Server.pm. $server->callback( 'process_page', &my_function ); $server->callback( 'validate_pager_id', &my_function ); $server->callback( 'validate_pager_pin', &my_function ); $server->callback( 'write_log', &my_function ); $server->callback( 'create_id_and_pin', &my_function ); process_page( $PAGER_ID, \%PAGE, @RESULTS ) $PAGER_ID = [ 0 => retval of validate_pager_id 1 => retval of validate_pager_pin ] $PAGE = { mess => $, responses => [], } validate_pager_id( PAGER_ID ) The return value of this callback will be saved as the pager id that is passed to the process_page callback as the first list element of the first argument. validate_pager_pin( VALIDATED_PAGER_ID, PIN ) The value returned by this callback will be saved as the second list element in the first argument to process_page. The PAGER_ID input to this callback is the output from the validate_pager_id callback. NOTE: If you really care about the PIN, you must use this callback. The default callback will return 1 if the pin is not set. write_log First argument is a Unix syslog level, such as "warning" or "info." The rest of the arguments are the message. Return value is ignored. create_id_and_pin Create an ID and PIN for a 2way message. custom_command() Create a custom command or override a default command in handle_client(). The command name must be 4 letters or numbers. The second argument is a coderef that should return a text command, i.e. "250 OK" and some "defined" value to continue the client loop. +++If no value is set, the client will be disconnected after executing your command.+++ If you need MSTA or KTAG, this is the hook you need to implement them. The subroutine will be passed the command arguments, split on whitespace. sub my_MSTA_sub { my( $id, $password ) = @_; # ... return "250 OK", 1; } $server->custom_command( "MSTA", &my_MSTA_sub ); disable_command() Specify a command to disable in the server. This is useful, for instance, if you don't want to support level 3 commands. $server->disable_command( "2WAY", "550 2WAY not supported here" ); The second argument is an optional custom error message. The default is: "500 Command Not Implemented, Try Again" handle_client() Takes the result of $server->client() and takes care of parsing the user input. This should be quite close to being rfc1861 compli- ant. If you specified Timeout to be something other than 0 in new(), SIGARLM will be used to set a timeout. If you use this, make sure to take signals into account when writing your code. fork()'ing before calling handle_client is a good way to avoid interrupting code that shouldn't be interrupted. forked_server() Creates a server in a forked process. The return value is an array (or arrayref depending on context) containing a read-only pipe and the pid of the new process. Pages completed will be written to the pipe as a semicolon delimited array. my($pipe,$pid) = $server->forked_server(); my $line = $pipe->getline(); chomp( $line ); my( $pgr, $pgr, %pagedata ) = split( /;/, $line ); AUTHOR
Al Tobey <tobeya@tobert.org> Some ideas from Sendpage::SNPPServer Kees Cook <cook@cpoint.net> http://outflux.net/ TODO
Add more hooks for callbacks Implement the following level 2 and level 3 commands 4.5.1 LOGIn <loginid> [password] 4.5.3 LEVEl <ServiceLevel> 4.5.5 COVErage <AlternateArea> 4.5.7 CALLerid <CallerID> 4.6.3 EXPTag <hours> 4.6.5 ACKRead <0|1> 4.6.6 RTYPe <Reply_Type_Code> SEE ALSO
Net::Cmd Socket perl v5.8.8 2008-02-04 Net::SNPP::Server(3pm)
All times are GMT -4. The time now is 04:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy