The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Improving Performance Through Persistent Connections iBot Oracle Updates (RSS) 0 04-06-2008 02:10 AM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 12:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 12:06 AM
Improving Unix Skills sak900354 UNIX for Dummies Questions & Answers 3 06-26-2006 02:03 PM
improving my script (find & replace) amir_yosha UNIX for Dummies Questions & Answers 8 12-15-2003 07:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-14-2004
Registered User
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
Lightbulb improving my script

Hi;

I want to access our customer database to retreive all clients that have as language index 2 or 3 and take their client number.
My input is a file containing all client numbers.
i access the data base using a function call "scpshow". The total number of clients i want to scan is 400 000 clients.

I tried this script using 100 subscriber it took 40 sec, and around 7% cpu time.

how can i improve my script to make it faster (IF it can ever be done).

#! /usr/bin
date
for sub in `cat /tmp/sublist `
do
lang=0
lang=`/IN/scp/test/scpshow/scpshow ul50 $sub | grep 'usr_int\[23\]' | awk '{print $2}'`

if [ $lang -eq 2 ] || [ $lang -eq 3 ];
then echo $sub >> /tmp/target
fi
done
date
cut -c 16-26 /tmp/target >> /tmp/final

thanks for your fast reply.
Reply With Quote
Forum Sponsor
  #2  
Old 07-14-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Replacing
Code:
for sub in `cat /tmp/sublist `
do
  ...
done
with
Code:
while read sub
do
  ...
done < /tmp/sublist
may well speed up the processing of the loop and avoid a useless use of cat....

If you're processing 400,000 records it's going to be slow whatever you do - you'd be better off writing it in C if you'll be running it often.


Cheers
ZB
Reply With Quote
  #3  
Old 07-14-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
What does the output from scpshow look like? And what shell are you really using? #!/usr/bin won't work.
Reply With Quote
  #4  
Old 07-14-2004
Registered User
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
scpshow output

the output is C300090B901900096393111222

i am calling the script #> ksh scritpname and it works...




Quote:
Originally posted by zazzybob
Replacing
Code:
for sub in `cat /tmp/sublist `
do
  ...
done
with
Code:
while read sub
do
  ...
done < /tmp/sublist
may well speed up the processing of the loop and avoid a useless use of cat....

If you're processing 400,000 records it's going to be slow whatever you do - you'd be better off writing it in C if you'll be running it often.


Cheers
ZB
Reply With Quote
  #5  
Old 07-14-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
You need to make that first line:
#! /usr/bin/ksh


If the output of "scpshow ul50 $sub" is:
C300090B901900096393111222

then I'm confused how the pipeline works. That grep is not going to match anything. And there is no 2nd field for awk to print.
Reply With Quote
  #6  
Old 07-14-2004
Registered User
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
sorry for miss-explanation

The output of scpshow is
.
.
.
usr_int[0] 0
usr_int[1] 9
.
.
usr_int[23] 1
usr_int[24] 3
.
.
.
i need to check the value of usr_int[23] if it is 2 or 3 i have to take stor the Sub. number.

I call scpshow in following way
>scpshow C300090B901900096393123345 <--"sub. numer"
and the output is the full profile of this specific sub (shown above) and i need to get all subs whose usr_int[23] =2 or 3.
the list of all sub. numbers is stored in the file "sublist". around 400,000 sub.
Reply With Quote
  #7  
Old 07-15-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
The fastest script would be:
Code:
#! /usr/bin/ksh
exec < sublist
while read sub ; do
        /path/to/scpshow  ul50 $sub | while read string lang ; do
                  [[ $string = 'usr_int[23]' ]]  && break
        done
        [[ $lang = $2 || $lang = 3 ]] && echo $sub >> /tmp/target
done
exit 0
This saves an awk and a grep for each iteration of the loop. You are still launching a scpshow process for each iteration of the loop. Unless scpshow can work with multiple subs at once, this can't be avoided.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0