Frank Herberger
2007-06-15 19:35:14 UTC
Hi there,
the following bash script snippet seems to be wrong and I cannot figure out
why. I hope you can help me as I am stuck with this for several days now.
if [ -x /bin/kill ]; then
PROCESSES="`getkill_list.sh`" # returns space sep. list of PIDs
if [ -n "$PROCESSES" ]; then
for PID in ${PROCESSES}; do
echo -e " - Killing process with PID ${PID}..."
/bin/kill -9 ${PID} >/dev/null 2>&1
done
fi
fi
# check which PIDs are on mounted /spfs filesystems
LINES="`grep '/spfs' /etc/mtab`"
# $LINES will now contain:
# /dev/mapper/vg01r5-lvol0 /spfs reiserfs rw,notail 0 0
# /spfs/mnt /spmnt none rw,bind 0 0
IFS=$'\n'
for i in ${LINES}; do # <-- problem occurs right here
if [ "`echo ${i} | awk '{print $2}'`" == "/spfs" ]; then
PIDS="`fuser -m /spfs | awk -F: '{print $2}'`"
elif [ -n "`echo ${i} | awk '{print $1}' | grep '^/spfs'`" ]; then
MPS_MOUNTED="${MPS_MOUNTED} `echo ${i} | awk '{print $2}'`"
fi
done
unset IFS
The problem now is: when the script is run for the first time,
getkill_list.sh will return a number of PIDs and the script will kill them
as intended. Afterwards, when it greps the lines out of /etc/mtab, the for
loop will fail:
./myscript.sh:471: syntax error: operand expected (error token
is "/dev/mapper/vg01r5-lvol0 /spfs reiserfs rw,notail 0 0")
When I now start it immediately again, getkill_list.sh will return no PIDs
as they have already been killed previously, so no killing is done this
time and now, the for loop runs through fine. $LINES have exactly the same
contents in both cases.
Can you give me a hint what goes wrong here?
Regards, Frank
the following bash script snippet seems to be wrong and I cannot figure out
why. I hope you can help me as I am stuck with this for several days now.
if [ -x /bin/kill ]; then
PROCESSES="`getkill_list.sh`" # returns space sep. list of PIDs
if [ -n "$PROCESSES" ]; then
for PID in ${PROCESSES}; do
echo -e " - Killing process with PID ${PID}..."
/bin/kill -9 ${PID} >/dev/null 2>&1
done
fi
fi
# check which PIDs are on mounted /spfs filesystems
LINES="`grep '/spfs' /etc/mtab`"
# $LINES will now contain:
# /dev/mapper/vg01r5-lvol0 /spfs reiserfs rw,notail 0 0
# /spfs/mnt /spmnt none rw,bind 0 0
IFS=$'\n'
for i in ${LINES}; do # <-- problem occurs right here
if [ "`echo ${i} | awk '{print $2}'`" == "/spfs" ]; then
PIDS="`fuser -m /spfs | awk -F: '{print $2}'`"
elif [ -n "`echo ${i} | awk '{print $1}' | grep '^/spfs'`" ]; then
MPS_MOUNTED="${MPS_MOUNTED} `echo ${i} | awk '{print $2}'`"
fi
done
unset IFS
The problem now is: when the script is run for the first time,
getkill_list.sh will return a number of PIDs and the script will kill them
as intended. Afterwards, when it greps the lines out of /etc/mtab, the for
loop will fail:
./myscript.sh:471: syntax error: operand expected (error token
is "/dev/mapper/vg01r5-lvol0 /spfs reiserfs rw,notail 0 0")
When I now start it immediately again, getkill_list.sh will return no PIDs
as they have already been killed previously, so no killing is done this
time and now, the for loop runs through fine. $LINES have exactly the same
contents in both cases.
Can you give me a hint what goes wrong here?
Regards, Frank
--
The ultimate performance killer for Unix environments:
tail -f /dev/zero > /dev/null
The ultimate performance killer for Unix environments:
tail -f /dev/zero > /dev/null