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.

In reply to Trying to pass variable output to subroutine by redcell184

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.