On Mar 23, 2004, at 9:12 AM, [EMAIL PROTECTED] wrote:
>> Hello,
>>
>> I have some code that is using backticks, executing commands on the
>> korn
>> shell.(if that matters). Most work as expected and i get the output
>> of the
>> shell command assigned to the variable left of the argument, like with
>> this
>> ls command and 'db2 connect' command.
>> <snips>
>> $is_dump = `ls $root_path$env/LOGS/ | grep dump`;
>I'm sure someone else will answer your questions suitably, so I'll take
>my chance to preach. ;)
preaching is welcome...
>Backticks should generally be avoided. The above works I'm sure, but
>you can't count on ls and grep to be available and function identically
>everywhere. What you can count on is Perl, this wonderful language you
>are already using. The above, Perlified, looks more like this:
this does have to run on multiple servers so that is a concern, but all
servers are identical in everyway
>opendir DIR, "$root_path$env/LOGS/" or die "Directory error: $!";
>my @files = grep m/dump/, readdir DIR;
>close DIR;
hmm, much better...i'll change that
>> $db_con = `db2 connect to $env user $dbuser using $dbpass`;
>> if ($db_con =~ /$env/) {
>Similarly, this looks like a job for the DBI.
i avoided DBI, in this instance, as all i'm doing is validating a
connection to the dbserver can be made, otherwise i would install and use
DBI, its not in my current install :( ...but that may change...
for now i'll take a combo of what you and wiggins offered..and consider
installing DBI on all the servers as well.
Thank You,
Jeff
James
> <snips />
>
> further down in my code i'm executing a shut down command and a start
> up
> command using the same method. and in each of these instances, i'm
> assigning the output of this command to the variable and adding it to
> the
> body of an email.
> <snips>
> $stop_cmd = `./psadmin -p stop -d $env`;
> $body .= $stop_cmd;
> sleep 60;
> $start_cmd = `./psadmin -p start -d $env`;
> <snips />
> the calls to the psadmin script prints to the shell and don't get
> assigned
> to the variable. but they work exactly as expected. Is there a
> better way
> to capture this output? i've tried some searching, but have not found
> which FM to R :).
>
> Thanks
> Jeff
>
>
>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>