Script not working...producing 0's and not number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not working...producing 0's and not number
# 1  
Old 12-02-2009
Script not working...producing 0's and not number

Below is my script:

Code:
 
#!/bin/sh
#echo "Please type oracle-lower case please:"
#read X
#if [[ "${X}" != "oracle" ]]
#then
#       echo "Sorry that is not oracle, try again"
#       exit 1
#else
#       echo Thank you
#fi
find / -name oracle 2>/dev/null |
while read line
do
        bdf 2>/dev/null | grep "$X" | awk 'BEGIN {total=used=free=0}
        {total +=$2
         used +=$3
         free +=$4}
 END    {print "total space for oracle: "total;
         print "free space available for oracle: "free;

If I run the entire script, the result is 0's. If I run it from the find down I get numbers? Why cant I run the whole script and come up with numbers?

Bigben

Last edited by jim mcnamara; 12-02-2009 at 06:23 PM.. Reason: add last [ / c o d e ] tag
# 2  
Old 12-02-2009
Part of the script is missing? There is no ending } and quote for the awk statement and the done statement of the while loop isn't there either.

It seems to me this script will find any path on the system that contains oracle. So if you have /oracle on your system it will list all subdirectories and files. Suppose that gives you 100 lines. The script will then enter the loop and since X is empty bdf will not get filtered. So what you end up with is 100 * a result of the total of all filesystems that are mounted on your host. It seems to me you do not need the while do loop and I am not sure why you need the find statement.

Last edited by Scrutinizer; 12-02-2009 at 06:58 PM..
# 3  
Old 12-02-2009
I did it!! I figured it out. This was my first script Ive wrote, Im so proud. Ive learned alot through this process-lol.

I added ${line} after bdf, then added > junk.txt before done, then after done entered cat junk.txt. And it works!!

I have also noticed that scripting is addicting!!

Now I want to echo the results of the find command?

do I add an echo ${line} before the while loop?

Bigben1220
# 4  
Old 12-02-2009
Quote:
Originally Posted by bigben1220
do I add an echo ${line} before the while loop?
Probably best if you echo it on a line after the "do".
# 5  
Old 12-02-2009
I added an echo ${line} after the do the | to the bdf
man that sounds confusing and Im the one writing it-lol.

Thansk Im waiting for the output now.
# 6  
Old 12-02-2009
Not sure you wanted to do that. I suppose I meant after the do and before the bdf.

I'm sharing your enthusiasm, though!

Code:
...
do
        echo $line
        bdf 2>/dev/null | grep "$X" | awk 'BEGIN {total=used=free=0}
...

# 7  
Old 12-02-2009
Dude your awesome!!

Its working....aw shucky ducky now....what script to tackle next...so many scripts to choose.

Thanks to all for the help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script not producing output

Hi, I have a text file with some thousands of rows of the following kind (this will be referred to as the inputFileWithColorsAndNumbers.txt): Blue 6 Red 4 Blue 3 Yellow 4 Red 7 Colors in the left column and a number in the right one for each line. I want to run an awk... (5 Replies)
Discussion started by: Zooma
5 Replies

2. Shell Programming and Scripting

Csh arithmetic not producing the expected value

My original post did not show up properly. I am trying again. I have a simple tsch script that does some basic arithmetic. The calculated value was not producing the result I was expecting. I wrote a sample script to illustrate the things that I tried. #!/bin/tcsh @ count = 43 @... (3 Replies)
Discussion started by: sgualandri
3 Replies

3. Shell Programming and Scripting

awk producing too many fields

Hey guys, awk is putting out too many results, two of each specifically. See below. Code: read CPU_VENDOR_ID <<< $(cat /proc/cpuinfo | grep "vendor_id" | awk -F: '{print $2}') echo $CPU_VENDOR_ID echo Output: AuthenticAMD AuthenticAMD I only want it to print out "AuthenticAMD" once. ... (7 Replies)
Discussion started by: 3therk1ll
7 Replies

4. IP Networking

Tcpdump -i any producing duplicate packages?

Hi, Can anyone explain why do I see same request twice in tcpdump package when I use "tcpdump -i any"? So I'm tracing packets on eth1.800 interface, but using "tcpdump -i any" to capture them. What I see is that the requests/responses from my side seem to appear as duplicate in the pcap file,... (1 Reply)
Discussion started by: Juha
1 Replies

5. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

6. Shell Programming and Scripting

Find highest number - working but need help!

Hello all, I am new to this and need some help or maybe steer me to the right direction! I wrote a script to get the highest number and prints it on the screen, the script basically asks the user to input numbers, and then prints the highest number! very simple it works like this $sh max.sh... (8 Replies)
Discussion started by: unknownsolo
8 Replies

7. UNIX for Dummies Questions & Answers

Script producing error, Program to calculate maximum number

Hi folks, Here i have written a shell script to calculate a maximum number from 10 numbers entered on command line. max=0 echo Enter 10 numbers , one at a time for i in 1 2 3 4 5 6 7 8 9 10 do read n max=`expr $max + $n` if --- At this last step there is some problem, it gives error... (5 Replies)
Discussion started by: rits
5 Replies

8. AIX

aix 4.2 : using dd of=/dev/rmt0 producing error

I want to compress backup files to tape using compress on our AIX 4.2 - Our TAR does not have compression. - I do not want to use local storage to compress as most of the filesystems are pretty full. - the only compressing tool we have is 'compress' - tapes are 5Gb 8mm I am trying this... (10 Replies)
Discussion started by: Browser_ice
10 Replies

9. Shell Programming and Scripting

sed in while loop producing arithmetic output

Hi all Just wondering if someone can help me with this. I'm trying to write a script that processes the output of another file and prints only the lines I want from it. This is only the second script I have written so please bare with me here. I have referred to the literature and some of the... (3 Replies)
Discussion started by: javathecat
3 Replies

10. Shell Programming and Scripting

number of working days

Hi There, Can you help me writing an unix script which tells me number of working days between two dates. say d1 and d2. The answer should be Integer. is it possible in Unix. cheers, (1 Reply)
Discussion started by: rahulkav
1 Replies
Login or Register to Ask a Question