redcell184 has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys i come to seek more knowledge of perl. I have created a simple process restart script for an application that sometimes fails. The application restarts it self at some point of the day and a special shell script has the new PID (bpps.sh.pid). I am trying to cat or look for the new PID from (bpps.sh.pid)then pass that output to the $PS variable in my sub routine so it can pin point the process and stop and restart it. I am also trying to execute 2 shell scripts by calling them with the exec() function, but that doesn't seem to work also. Can someone please assist me This is the script i created:
#!/usr/bin/perl -w $PID=`cat /export/home/weblogic/bai/bpps.sh.pid`; print "Checking\n"; check_for_bpps(); sub check_for_bpps { $PS=`ps -eaf | grep $PID`; if ($PS =~ /bpps/) { print "output from ps is: $PS\n"; } else { print "Stopping process and restarting process\n"; exec(`sh -c /export/home/weblogic/bai/bpps.sh stop;sh -c /expo +rt/home/weblogic/bai/bpps.sh start 2 > /dev/null 2>&1`); } }
And this is the output i receive from it:
Checking Stopping process and restarting process /export/home/weblogic/bai/bpps.sh: //.profile: No such file or directo +ry sh: usage:: not found
Thanks in advance.

Replies are listed 'Best First'.
Re: Trying to pass variable output to subroutine
by shmem (Chancellor) on Nov 08, 2007 at 14:51 UTC
    exec(`sh -c /export/home/web

    Nope. Don't use backticks here. You are executing those scripts and trying to execute whatever those scripts have sent to STDOUT. Is that really what you want to do?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Trying to pass variable output to subroutine
by cdarke (Prior) on Nov 08, 2007 at 16:40 UTC
    You might also want to add some quotes:
    exec('sh -c "/export/home/weblogic/bai/bpps.sh stop";sh -c "/export/home/weblogic/bai/bpps.sh start" 2> /dev/null 2>&1');
Re: Trying to pass variable output to subroutine
by redcell184 (Initiate) on Nov 12, 2007 at 21:52 UTC
    ok removing the ticks and adding double qoutes worked, but now i have another dilema i want to substitute my $PS variable with the following:
    $PS=`/usr/ucb/ps -auwwwx | awk '/bpps/{ print $2 }'`;
    When i run the program in the regular bash shell i get a list of PIDS which is the result i want. When i add that same statement to $P variable i get the following:
    Checking Use of uninitialized value in concatenation (.) or string at bpps-2 li +ne 8.