Visit Our UNIX and Linux User Community

shell script takes long time to complete

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script takes long time to complete
# 1  
Old 02-05-2007
Data shell script takes long time to complete

Hi all,

I wrote this shell script to validate filed numbers for input file. But it take forever to complete validation on a file. The average speed is like 9mins/MB.

Can anyone tell me how to improve the performance of a shell script?

# 2  
Old 02-05-2007
It would be great if you could post sample input / output data and if possible your script Smilie
# 3  
Old 02-05-2007
Question Don't have the script right here with me


I don't have the script right here with me, but I can brief you how my script looks like.

    #starts with couple of constants for the file
    function1 ...
    function2 ...
    while time < 00:00:00
       if [ $? -eq 0 ]
           for loop 

Will this help to determine the cause?
# 4  
Old 02-05-2007
There could be something in those functions that is taking too much of a time. For example, some cut or some grep or an invocation of some external tools. Also the script, call_another_script could be the culprit.

Unless you can show what those functions are, it is hard to pinpoint the exact cause.
# 5  
Old 02-05-2007
Put some "date" commands in your script and you might be able to find out where the delay is and focus on that part.
# 6  
Old 02-05-2007
I would start by setting the debug flag in the shell. It might be obvious just from that what operation is taking the time, without knowing exactly what you are doing in the functions it is not really possible for anyone to answer.
# 7  
Old 02-05-2007
Thanks for the reply

the part that take the most of the time is the following code.

function line_count
       COUNT=`echo $1 | awk -F\| '{print NF}'`
       if [ "$COUNT" != "$2" ]
          error_log "File $FN: Validation failed at line   $LINENUM. Expected $2, getting $COUNT"
          return 5

   function validate_line
        if [ "$1" = "$FIRST_LEVEL_HEAD" ]
              line_count "$2" $FIRST_LEVEL_COUNT
              return $?
        elif [ "$1" = "$SECOND_LEVEL_HEAD" ]
              line_count "$2" $SECOND_LEVEL_COUNT
              return $?
              error_log "File $FN: Line $LINENUM head is not regconised"
              return 5

   function validate_file
      trace_log "Start to validate $FN..."
       while read LINE
            LINENUM=`expr $LINENUM + 1`
            LINE_HEAD=`echo $LINE | awk -F\| '{print $1}'`
            validate_line $LINE_HEAD "$LINE"
            if [ ! $? -eq 0 ]
       done < $1
       if [ ! $ERROR -eq 0 ]
           return 7

    validate_file $FILE

Any suggestion ?

Previous Thread | Next Thread
Test Your Knowledge in Computers #850
Difficulty: Medium
Every Bluetooth device has a unique 48-bit address.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking for substring in a loop takes too long to complete.

I need to check if the files returned by ls command in the below script is a sub-string of the argument passed to the script i.e $1 The below script works fine but is too slow. If the ls command take 12 secs to complete printing all files with while loop then; using posix substring check... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Script takes too long to complete

Hi, I have a lengthy script which i have trimmed down for a test case as below. more #!/bin/bash paths="allpath.txt" while IFS= read -r loc do echo "Working on $loc" startdir=$loc find "$startdir" -type f \( ! -name "*.log*" ! -name "*.class*" \) -print | while read file do... (8 Replies)
Discussion started by: mohtashims
8 Replies

3. UNIX for Advanced & Expert Users

Find command takes too long to complete

Hi, Below is my find command find /opt/app/websphere -name myfolder -perm -600 | wc -l At time it even takes 20 mins to complete. my OS is : SunOS mypc 5.10 Generic_150400-09 sun4v sparc SUNW,T5440 (10 Replies)
Discussion started by: mohtashims
10 Replies

4. Shell Programming and Scripting

Wget takes a long time to complete

Hi, I wish to check the return value for wget $url. However, some urls are designed to take 45 minutes or more to return. All i need to check if the URL can be reached or not using wget. How can i get wget to return the value in a few seconds ? (8 Replies)
Discussion started by: mohtashims
8 Replies

5. UNIX and Linux Applications

database takes long time to process

Hi, we currently having a issue where when we send jobs to the server for the application lawson, it is taking a very long time to complete. here are the last few lines of the database log. 2012-09-18- E244403536A576 LEVEL: Warning PID : 950492 ... (1 Reply)
Discussion started by: techy1
1 Replies

6. Shell Programming and Scripting

sort takes a long time

Dear experts I have a 200MG text file in this format: text \tab number I try to sort using options -fd and it takes very long! is that normal or I can speed it up in some ways? I dont want to split the file since this one is already splitted. I use this command: sort -fd file >... (12 Replies)
Discussion started by: voolek
12 Replies

7. UNIX for Dummies Questions & Answers

time how long it takes to load a module

Hello, like the title says, how can i measure the time it takes to load a module in Linux, and how how can i measure the time it takes to load a statically compiled module. /Best Regards Olle ---------- Post updated at 01:13 PM ---------- Previous update was at 11:54 AM ---------- For... (0 Replies)
Discussion started by: ollebanan
0 Replies

8. Shell Programming and Scripting

<AIX>Problem in purge script, taking very very long time to complete 18.30hrs

Hi, I have here a script which is used to purge older files/directories based on defined purge period. The script consists of 45 find commands, where each command will need to traverse through more than a million directories. Therefore a single find command executes around 22-25 mins... (7 Replies)
Discussion started by: sravicha
7 Replies

9. Linux

it takes long time to login on server

Hi, I am trying to login using ssh on Red Hat Linux 5 server, The password appears immediately but after I enter the password it takes about 90 seconds to login completely. Please suggest what changes require? Regards, Manoj (4 Replies)
Discussion started by: manoj.solaris
4 Replies

10. Programming

fwrite takes extremely long time

After my previous thread, I think I found out what causes the long delays. I run this program on several Linux computers, and the sometimes (after the file with the arrays becomes big) the fwrite takes between 100 ms to 900 ms. This is very bad for me, as I want a timer to halt each 30 ms.... ... (5 Replies)
Discussion started by: inna
5 Replies

Featured Tech Videos