Start a Conversation

Unsolved

This post is more than 5 years old

431

March 23rd, 2009 08:00

automated / server tool --> perlscript: how to get parameters ?

All,

we actually switch from shell scripts to perl. New ones will be written in perl, what works like a charm.

I have a shell script running, dealing with the parameters like SM_Obj_Name, what needs to be "converted" to perl.

I'm runing into problems with server / automated tools invoking this perlscript.

The script itself is located in local/actions/server, world executable and also is executed, what i can see so far in the appropriate logfile.

When I invoke the command on the shell and hand over test parameters like this "./perscript.pl 1 2 3 4 5" it writes the contents of @ARGV into the defined file.

When its invoked as an automated server script, it only inserts the "static" part defined in the script, but no parameters.

The part what should parse and writ this is this one:

foreach my $num (0 .. $#ARGV) {
print MYFILE "$ARGV[$num]\n";
}

It SHOULD take all parametes handed over to the script and write them one after another into the logfile until end of @ARGV, but nothing is seen.

Tried to find an anser here and in knowledgbase without success.

I expected something like "perlscript.pl para1 para2 para3" but it seems that is not the case.
Maybe somebody can point me some information on how those parameters are handed over from SAM / Tools or can be retrieved by perl script.

Thanks in advance.

Christian

EDIT:
Forgot to mention...
Solaris 5.8 sparc
Perl 5.8.9
SAM 6.5

Message was edited by:
choefing

49 Posts

March 23rd, 2009 08:00

Sometimes.. 5 minutes of more investigation.. prevents posting in forum ...

Got it working now, you can find a example of what I was searching for in actions/client/SmGetEnv.pl


# ------------ Here is the Perl script ---------------

# Get count of command line parameters
$n = $#ARGV;


# Get the parameters. Each parameter is in format: "key=value"

for ($i = 0; $i <= $n; ++$i) {
$ARGV[$i] =~ /^"*([^=]+)=(.*?)"*$/; # Split key from value,
# using first '=' in text string as delimiter
$ENV{$1} = $2; # create the ENV variable and assign its value
}


# Your script code goes here. We will just print out all environment variables.
# This includes the variables assigned above, as well as any system-supplied items

foreach $key (sort keys %ENV) {
print $key . "=\"" . $ENV{$key} . "\"\n";
}
No Events found!

Top