0

I'm new to scripting languages and I want to to ask simple question.

#!/usr/bin/perl

my $process_id = shift;
execute();

sub execute() {
  system("cd", "bin");
  my $output = `pcp.sh -p $process_id`;
  if (index($output, "some string") != -1) {
    print("Information 1.0 :Standalone server works fine \n");
  }
  else {
    print("Information 2.0 Standalone server have some problems)\n");
  }
}

for 'pcp.sh' follow the link :

http://www.oracle.com/technetwork/systems/security/pcp-149863.txt

This script works on terminal and returns

Information 1.0 Standalone server works fine

But I'm doing script monitoring and monitoring tool gets the output as return value. (It is very strange.) On monitoring tool while I'm running the script it says

Information 2.0 Standalone server have some problems

I need to get output from pcp.sh. And this pcp.sh -p $process_id part of that code is running for about one minute. The monitoring tool runs for maybe five seconds. I undrstand that I have to wait, but I don't know how to handle this job.

Hayra
  • 456
  • 2
  • 7
  • 22
  • http://stackoverflow.com/q/799968/223226 – mpapec May 08 '14 at 11:40
  • The backticks don't return until the command complete. Any output you see after the backticks return doesn't come from the program you launched, but from a program it launched in the background. Perl doesn't know about it. How could it? Even you didn't know about it. – ikegami May 08 '14 at 11:42
  • What is the point of your "system()" call? And what is the point of "abs(1.0)"? – Mark Setchell May 08 '14 at 11:49
  • system call just go to bin directory from $home directory, the others are not needed and i deleted. – Hayra May 08 '14 at 11:51
  • 1
    Note that `system("cd", "bin");` does nothing. It tries to execute a program named `cd`, but there is no such program, so it returns -1 and sets `$!` accordingly. There is a shell builtin named `cd`, but that would only change the work directory for that shell if you managed to get a shell to run it. You want the Perl builtin `chdir`. – ikegami May 08 '14 at 11:57
  • I changed the code chdir to /my/location but it still returns from tool wrong information. – Hayra May 08 '14 at 12:05

1 Answers1

0

Try using the Perl debugger to work it out. It is easy to use, just run:

perl -d yourscript

and it will start. Then you can use the following commands:

n - run next statement

l - list perl script

p var - print some variable

s - step into a function (rather than executing entire function)

b 16 - set breakpoint on line 16

r - run until next breakpoint or end

q - quit

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • that didn't work problem is not executing. My other script pcp.sh must be executed fully but tool doesn't execute like this even though terminal executes correctly – Hayra May 08 '14 at 14:12
  • http://www.oracle.com/technetwork/systems/security/pcp-149863.txt it is given in that link works to find open TCP ports and PIDs related in Solaris. – Hayra May 14 '14 at 06:44