If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > [bash} for loop problem...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-04, 15:41
TimoV TimoV is offline
Registered User
 
Join Date: Dec 2003
Posts: 56
Unhappy [bash} for loop problem...

I'm confused....I'm trying to make a little script on my Mandrake box in the bash shell. I admin AIX and use the ksh for my usual scripting, but seeing as they follow the same basics I figured this script would be easy...

What I got is the following:

Code:
DATE=`date +%H%M`
    for i in `df -k -P | grep -v File | grep -v "/proc" | awk '{ print }'`
    do
    USAGE=`df -k -P | grep ${i} | awk '{ print $5 }'| sed s!%!!g`
    INDEX=`mysql -D sysmon -e "select * from iostat" | awk '{ print }' | tail -1`
    INDEX=`expr ${INDEX} + 1`
    mysql -D sysmon -e "insert into iostat values ('${INDEX}', '${DATE}', '${i}', '${USAGE}') ;"
    done
When I run this i get the following error:

Quote:
: command not foundine 20:
: command not foundine 21:
'/gather_data.sh: line 24: syntax error near unexpected token `do '/gather_data.sh: line 24: `do
Now if I run a simular for loop in a shell manually there are no problems....But I can't for the live of me figure out what I did wrong. Tried adding a few ';' here and there, but that didn't help.

Tried switching to use a temp file and load that into MySQL, but all temp files my script makes have na '?' behind the filename, so they get filled but I can't read them from the script....

Any clues how I can get this to work?
Reply With Quote
  #2 (permalink)  
Old 02-10-04, 17:03
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
I can't see where is the error, perhaps your for statement (you take the full result of the df command, your awk command filter nothing).

The INDEX assigment doesn't care of the file system, if it is correct put it outside the for loop.

Try and adapt this script :

Code:
DATE=`date +%H%M`
df -k -P | tail +2 | \
while read Filesystem Kblocks Used Available Capacity Mountedon
do
    USAGE=${Capacity%%%}
    INDEX=$(( $(mysql -D sysmon -e "select * from iostat" | tail -1) + 1))
    (( INDEX = USAGE + 1 ))
    mysql -D sysmon \
          -e "insert into iostat values \
             ('${INDEX}', '${DATE}', '${Filesystem}', '${USAGE}') ;"
done
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On