Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003

    Unhappy Unanswered: [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:

    DATE=`date +%H%M`
        for i in `df -k -P | grep -v File | grep -v "/proc" | awk '{ print }'`
        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}') ;"
    When I run this i get the following error:

    : command not foundine 20:
    : command not foundine 21:
    '/ line 24: syntax error near unexpected token `do '/ 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?

  2. #2
    Join Date
    Jan 2004
    Bordeaux, France
    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 :

    DATE=`date +%H%M`
    df -k -P | tail +2 | \
    while read Filesystem Kblocks Used Available Capacity Mountedon
        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}') ;"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts