Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Convert Korn shell echo status to Perl

Posted on 2008-11-02
5
443 Views
Last Modified: 2010-05-18
I have the following two UNIX Korn shell commands. The semi-colon is needed instead of the pipe symbol after the grep statement otherwise it doesn't work:

chk_auto_up | grep AUTOSYSDB; echo $?
it returns a 0

chk_auto_up | grep AUTOSYSDB2; echo $?
it returns a 1

Both of these shell statements are returning the correct echo status.

When I run this command as Perl:
system("chk_auto_up | grep AUTOSYSDB | echo $?");
or
system("chk_auto_up | grep AUTOSYSDB2 | echo $?");

they both return a 0

The "chk_auto_up" command is an AutoSys command which checks databases.

thanks
0
Comment
Question by:rkckjk
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 22860745
system("chk_auto_up | grep AUTOSYSDB2 | echo $?")

should be

system("chk_auto_up | grep AUTOSYSDB2 ; echo $?")
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 22860752
Sorry, I didn't test beforehand.

You could do
my $result = `chk_auto_up | grep AUTOSYSDB2`;
 
if ($result) {
  print "Exists\n";
}
else {
  print "Does not exist\n";
}

Open in new window

0
 
LVL 2

Author Comment

by:rkckjk
ID: 22860761
Doesn't work it returns 0.
0
 
LVL 2

Author Comment

by:rkckjk
ID: 22860780
Doesn't work it comes back with Exists
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22863245
Really?  Can you please show me this behaviour by adding a print before the if test.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question