Script help needed...



Hi All,

I'm writing a script that I am going to use to test write data to an nfs
mount. I'm having problem with a variable. The variable R is set inside a
while loop and it is null outside the loop even after it is set.

Here is a code snippet. I've attached the whole script if anyone would like
to look at the whole thing.

if [ ! -f $PIDFILE ]; then
touch $PIDFILE
else
# Read PIDFILE and determine if script is already running.
cat $PIDFILE | while read LINE
do
if [ -z "$LINE" ]; then
break
else
#Get PID from PIDFILE
OLDPID=`echo $LINE | awk '{ print $1 }'`
RUNNING=`ps aux | grep $OLDPID | grep -v grep | wc -l | tr -d '
'`
if [ $RUNNING = 0 ]; then
R=0
else
(( R = $R + 1 ))
echo $R
LOC=`echo $LINE | awk '{ print $2 }'`
fi
fi
done
fi
echo "R = $R"

The last echo is null even after R is set inside the loop and I don't
understand why.

Thanks,

--
Magnus Andersen
Systems Administrator / Oracle DBA
Walker & Associates, Inc.
-- redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list


Relevant Pages

  • RE: Script help needed...
    ... I believe that the problem is that the `cat | while` syntax starts a sub-shell, changing the scopes of the variables. ... I'm writing a script that I am going to use to test write data to an nfs ... while loop and it is null outside the loop even after it is set. ... # Read PIDFILE and determine if script is already running. ...
    (RedHat)
  • [SLE] Converting 9.3 CD ISOs to a DVD ISO
    ... I attach the script I got from a friend for converting the five ... downloadable CD ISO images to a single DVD ISO image. ... mount SUSE-9.3-Prof-i386-CD2.iso CD2 -o loop ...
    (SuSE)
  • Re: Report in FM 6 or 7
    ... achieve this report format will have to be done via scripting. ... but they will simplify the script and Sort Order. ... End Loop ... The normal 'Dancer' field is used so that if there are more than one ...
    (comp.databases.filemaker)
  • Re: recreate database script not work
    ... I got a script which is supposed to regenerate database systax. ... REM gen_dbse_9.sql ... end loop; ...
    (comp.databases.oracle.server)
  • Re: Array, foreach problem
    ... I'm stuck on using an array to determine the out come of a foreach loop. ... The script is below. ... Shlomi Fish http://www.shlomifish.org/ ...
    (perl.beginners)