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

I have a requirement where i need to integrate shell command to perl. I am aware how to do it.

But, i need to run this shell cmd (which is snmp walk for 20 mibs repeatedly) at the beginning of the script and stop only after all other executions (say, testcases) are over

to be more precise, run this shell cmd at the background and stop when the script finishes its whole execution

.

I was thinking 2 options. One is use a subroutine and add this shell cmd inside and call after each testcases. There is a problem with this. The shell will start and stop after each call, which i dont want

.

Do you have any suggestions

Replies are listed 'Best First'.
Re: Integrating shell cmd to perl script
by Anonymous Monk on Mar 25, 2015 at 08:45 UTC

    The shell will start and stop after each call, which i dont want

    Why not?

      If i call the subroutine (which has the shell cmd), each time from different part of the script, control goes to the subroutine and executes the shell command. The problem here is , when it enters the subroutine and executes the shell cmd it wait take x time to finish the task, which means it is a separate activity. This is what i do not want. Instead, my shell cmd should not have any connections to my other areas/testcases in the script. It should be a complete isolated thread/activity. It should start, execute on its own, finally it should pass the control back, when the script is completed

        Why don't you change the shell script to perform a loop and then use either system( 1, 'shellscript') or my $pid= open( my $fh, 'shellscript |' ) to launch it in the background? You can then kill the shell script when your main program exits.

Re: Integrating shell cmd to perl script
by sandy105 (Scribe) on Mar 26, 2015 at 11:30 UTC

    i am not sure what your command is but you could make it a background process by adding "&" to end so it continues running