Slow Script Execution.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Slow Script Execution.
# 15  
Old 06-22-2011
Quote:
Originally Posted by mohtashims
Let me know if i missed anything.
Again, the $1's inside awk have nothing to do with the $1's in your shell. They're in single quotes.

Code:
 echo '$1'
$1

So you're feeding a literal $1 into awk, not the script's first parameter, and don't need to change it to $2 to avoid your $1. Awk understands $1 as "the first token in the record".
# 16  
Old 06-22-2011
It does not work with $1 either.

Yes, because this is what i actually do inside the original script that i am trying to incorporate this into.

nettest.sh

Code:
#!/bin/ksh
echo "Your PID is $1"
free=`netstat -an -f inet | awk '
$1 ~ /\.[0-9]+$/ { p = $1
        while (i = index(p, ".")) p = substr(p, i+1)
        if (0+p >= 32768) a[0+p] = 1 }
/SCTP/ { for (p in a) count++
        print 32768 - count }'`
echo Free ports $free
echo "Your PID is $1"


output:
./"nettest.sh" 4456
Your PID is 4456
Free ports
Your PID is 4456[/CODE]

I hope I am able to cascade correctly what I am trying to do.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by mohtashims; 06-22-2011 at 04:59 PM.. Reason: once again - please use code tags!
# 17  
Old 06-22-2011
OK maybe I was incorrect in removing the END {} block. Maybe your netstat doesn't have SCTP as mine does. But we'll keep it in there just in case, since i dont use solaris and am unsure if that section comes and goes. heh.

Code:
free=`netstat -an -f inet | awk '
$1 ~ /\.[0-9]+$/ { p = $1
        while (i = index(p, ".")) p = substr(p, i+1)
        if (0+p >= 32768) a[0+p] = 1 }
$1 ~ /SCTP/ { exit }
END { for (p in a) count++
        print 32768 - count }'`

echo Free ports $free

This User Gave Thanks to neutronscott For This Post:
# 18  
Old 06-22-2011
Hi,

This is what I see with the lastest you shared.
Code:
echo "Your PID is $1"
free=`netstat -an -f inet | awk '
$1 ~ /\.[0-9]+$/ { p = $1
        while (i = index(p, ".")) p = substr(p, i+1)
        if (0+p >= 32768) a[0+p] = 1 }
$1 ~ /SCTP/ { exit }
END { for (p in a) count++
        print 32768 - count }'`
echo Free ports $free
echo "Your PID is $1"

 
./"nettest.sh" 4456
Your PID is 4456
Free ports 0
Your PID is 4456

The output is "Free ports 0" even if i don't read my PID using $1.

Last edited by Scott; 06-22-2011 at 04:41 PM.. Reason: Code tags
# 19  
Old 06-22-2011
How about you post what your netstat output looks like so us blind men can stop bothering this elephant?
# 20  
Old 06-22-2011
Here you go:
Code:
bash$> netstat -an -f inet
UDP: IPv4
Local Address Remote Address State
-------------------- -------------------- ----------
*.40473 Idle
*.41371 Idle
*.36689 Idle
*.61401 Idle
*.41391 Idle
*.111 Idle
*.* Unbound
*.33067 Idle
*.46783 Idle
*.* Unbound
*.33072 Idle
 
and so on .... scrolling down the line i see
 
*.45175 Idle
*.34185 Idle
TCP: IPv4
Local Address Remote Address Swind Send-Q Rwind Recv-Q State
-------------------- -------------------- ----- ------ ----- ------ -----------
169.81.183.182.58316 169.81.183.188.10055 263536 0 263536 0 CLOSE_WAIT
169.81.183.182.57926 169.81.183.188.10055 263536 0 263536 0 CLOSE_WAIT
169.81.183.182.56846 169.81.183.188.10055 263536 0 263536 0 CLOSE_WAIT
169.81.183.182.55769 169.81.183.188.10055 263536 0 263536 0 CLOSE_WAIT

FYI... the initial script you shared did work.
Code:
#!/bin/sh
netstat -an -f inet | awk '
$1 ~ /\.[0-9]+$/ { p = $1
        while (i = index(p, ".")) p = substr(p, i+1)
        if (0+p >= 32768) a[0+p] = 1 }
/SCTP/ { exit }
END { for (p in a) count++
        print "Ports in use: " count "  Free: " 32768 - count }'


Last edited by Scott; 06-22-2011 at 04:43 PM.. Reason: Code tags
# 21  
Old 06-22-2011
Maybe it's just /bin/sh vs /bin/ksh. It works both ways for me. This is my test system:

Code:
[mute@sunny ~]$ uname -a
SunOS sunny 5.10 Generic_141444-09 sun4u sparc SUNW,Sun-Blade-100

I really don't know the matter at the moment. I prefer using bash for everything. Start it with bash, maybe try a printf instead... I dunno.

Code:
#!/bin/bash
free=`netstat -an -f inet | awk '
$1 ~ /\.[0-9]+$/ { p = $1
        while (i = index(p, ".")) p = substr(p, i+1)
        if (0+p >= 32768) a[0+p] = 1 }
$1 ~ /SCTP/ { exit }
END { for (p in a) count++
        printf("%d", 32768 - count) }'`

echo Free ports $free

Otherwise maybe someone else can pick this up. I'll be unable to for the next couple hours.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Script execution is very slow when trying to find all files and their owners on HP-UX box

Hi, I have a HP-UX server were I need to list all the files in the entire file system, their directory path, last modified date, owner and group. I do not need to search the file contents. I created the script given below and I am excluding directories and files of type tmp, temp and log. The... (4 Replies)
Discussion started by: Adyan Faruqi
4 Replies

2. Shell Programming and Scripting

Shell script reading file slow

I have shell program as below #!/bin/sh echo ======= LogManageri start ========== #This directory is getting the raw data from remote server Raw_data=/opt/ftplogs # This directory is ready for process the data Processing_dir=/opt/processing_dir # This directory is prcoessed files and... (4 Replies)
Discussion started by: Chenchireddy
4 Replies

3. Shell Programming and Scripting

Script to alert about a slow link on the website

Hello all, Currently I am using a script with "curl" to get the an alert if 200 ok would not be grepped.and the link is down. is it possible to get an alert mail if a particular link on a website is not completely down but SLOW?? (0 Replies)
Discussion started by: chirag991
0 Replies

4. Shell Programming and Scripting

Slow down output from dhclient-script to screen

Hi I know the basic about script and sleep processes. However this is more tricky: I would like to run sh -x /sbin/dhclient-script and slow down the output of the script as a whole. How would you do it? I would like to delay output on the screen with 1 second for every line for the output... (3 Replies)
Discussion started by: medium_linux
3 Replies

5. UNIX for Dummies Questions & Answers

Help with slow KSH script

My script builds a lot of these array lists, then compares their sizes which solves my problem, but runs very slow. :( set -A comboSorted -- $( for x in ${IDs} do nawk -v s=$x ' BEGIN { testPattern="^" s "$" } { if ( $2 ~ testPattern ) { getline;getline; if ($1 == "IMAGE_SIZE") print... (1 Reply)
Discussion started by: nerdcurious
1 Replies

6. Shell Programming and Scripting

Slow Perl script: how to speed up?

I had written a perl script to compare two files: new and master and get the output of the first file i.e. the first file: words that are not in the master file STRUCTURE OF THE TWO FILES The first file is a series of names ramesh sushil jonga sudesh lugdi whereas the second file (could be... (4 Replies)
Discussion started by: gimley
4 Replies

7. Shell Programming and Scripting

Bash script too slow

I have a bash script that will take approx. 130 days to complete. I am trying to grep a list of 1,144 user ID's out of 41 (1 GB each) files. The 41 files were originally one 41 G file, but that was horrendously too slow.:eek: This is my current file: #!/bin/bash for i in `cat... (11 Replies)
Discussion started by: tigta09
11 Replies

8. Shell Programming and Scripting

script to add numbers is slow

Hi, I am running a BASH shell with the following script. The script works and gives me correct output but is very slow with large files. The more rows and columns (width and height) the slower as you can probably see. How can I do what I want more efficiently? Any ideas welcome. It has been... (10 Replies)
Discussion started by: macsurveyr
10 Replies

9. Shell Programming and Scripting

slow command execution?

Dear World, I just wrote a script, which puzzled me somewhat. The siginficant code was: for file in `ls splits*`; # splits* came from a split command executed earlier do tail -$SomeNumber $file | cut -d" " -f6 > $file; done; The interesting thing is this: A few of the $files were... (2 Replies)
Discussion started by: BandGap
2 Replies

10. UNIX for Advanced & Expert Users

My script runs too slow :-(...

Hello experts, I have a series issue in script that result with bad peformence and I wonder if you can assist me. For example I have two files: File-New, size 15Mb. File-Old, size 1Mb. File-New content: a b c k File-Old content: d f a b (0 Replies)
Discussion started by: roybe
0 Replies
Login or Register to Ask a Question