in reply to Re^2: Creating process restart script
in thread Creating process restart script

Since you have not provided any sample output of your ps command (piped through grep and awk), I can only guess that you expect it to return a single string on a single line. Based on the "if" statement in your original code, I assumed that if the output of ps was not equal to the magic literal string 'weblogic', then you wanted to execute your $com2 command.

Does this answer your question?

Replies are listed 'Best First'.
Re^4: Creating process restart script
by redcell184 (Initiate) on Nov 01, 2007 at 06:13 UTC
    Here is the out put of the command shell command
    ps -eaf | grep bpps | grep -v grep | awk '{print $1,$10}' weblogic start weblogic /export/home/weblogic/bai/bpps.sh
    I have also tried compiling it and i get the following error message:
    Use of uninitialized value in concatenation (.) or string at bp1 line +3.
      If you need help debugging that compile error, you'll have to show what line 3 is.

      Otherwise, I think the following is what you are looking for:

      #!/usr/bin/env perl use warnings; use strict; my $com1; # replace call to ps with your ps output for this example: $com1 = <<EOF; weblogic start weblogic /export/home/weblogic/bai/bpps.sh EOF print "1st\n"; check_for_bpps($com1); # now assume that ps show that bpps is NOT running: $com1 = 'foo bar'; print "2nd\n"; check_for_bpps($com1); exit; sub check_for_bpps { my $com1 = shift; if ($com1 =~ /weblogic/) { print "bpps is running.\n"; } else { print "running com2.\n"; #$com2 = `sh -c /export/home/weblogic/bai/bpps.sh start 2 > /d +ev/null 2>&1`; } }

      When I run this, I get the following output:

      1st bpps is running. 2nd running com2.

      The key here is that I'm using a regular expression to search for the 'weblogic' string in your ps output.

        This variable below is my start up script:
        $com2 = `sh -c /export/home/weblogic/bai/bpps.sh start 2 > /d +ev/null 2>&1`
        I want to know how can i run this with root access. What format should it be in? The shell restart script is only going to be used for now i am going to convert it to perl integrate it into the script, but once i starting learning how to walk on my own. I do get the flow of the script. Thanks in advance.