Loading ...
Sorry, an error occurred while loading the content.

Trapping Strange Output

Expand Messages
  • Joe Catanzaro
    Bear with me, the way I ve worded the question makes it seem unrelated to Perl, but it s what I m trying to pull into my script. My main point of reference is
    Message 1 of 6 , Apr 1, 2004
    • 0 Attachment
      Bear with me, the way I've worded the question makes it seem unrelated to
      Perl, but it's what I'm trying to pull into my script. My main point of
      reference is the Perl Cookbook, recipe 16.7 Reading STDERR from a Program.

      I'm trying to trap the output of the following command.

      ssh -l user1 box1 -o BatchMode=yes ". /export/home/user1/.profile 2>&1
      1>/dev/null;. /home/superuser/fixer/sync.user1.env;/home/superuser/fixer
      78758000002063 002 X"

      When I run the command by itself, outside of ssh, the results are as
      follows, which is exactly what I want:

      user1 > . /export/home/user1/.profile 2>&1 1>/dev/null;.
      /home/superuser/fixer/sync.user1.env;/home/superuser/fixer/fixer
      78758000002063 002 X
      GETTING CCWO DATA . . .
      PACKING GETAD DATA . . .
      sp [124]
      obj_count [61]
      data [640023710002374000078758000002063002000000000000000000000000000]
      (FLDID(3)) 0
      (FLDID(33554436)) 9
      (FLDID(201326597)) 238\1f0\1f0\1f0\1f\1f0\1f100\1f0\1f0\1f

      Segmentation Fault(coredump)

      But when I run it through ssh, it doesn't return any output. Here are the
      following variations that I've tried and each time I get nothing.

      ssh -l user1 box1 -o BatchMode=yes ". /export/home/user1/.profile 2>&1
      1>/dev/null;. /home/superuser/fixer/sync.user1.env;/home/superuser/fixer
      78758000002063 002 X 2>&1" # Trapping both STDERR and STDOUT

      ssh -l user1 box1 -o BatchMode=yes ". /export/home/user1/.profile 2>&1
      1>/dev/null;. /home/superuser/fixer/sync.user1.env;/home/superuser/fixer
      78758000002063 002 X 2>/dev/null" # Trapping STDOUT and dumping STDERR

      ssh -l user1 box1 -o BatchMode=yes ". /export/home/user1/.profile 2>&1
      1>/dev/null;. /home/superuser/fixer/sync.user1.env;/home/superuser/fixer
      78758000002063 002 X 2>&1 1>/dev/null" # Trapping STDERR and dumping
      STDOUT

      ssh -l user1 box1 -o BatchMode=yes ". /export/home/user1/.profile 2>&1
      1>/dev/null;. /home/superuser/fixer/sync.user1.env;/home/superuser/fixer
      78758000002063 002 X 3>&1 1>&2 2>&3 3>&-" # Exchanging STDERR and STDOUT

      I'm at a loss. Any input would be very appreciated.

      Thanks,


      Joe Catanzaro
      joecatanzaro@...
    • merlyn@stonehenge.com
      ... Joe But when I run it through ssh, it doesn t return any output. Here are the Joe following variations that I ve tried and each time I get nothing. The
      Message 2 of 6 , Apr 1, 2004
      • 0 Attachment
        >>>>> "Joe" == Joe Catanzaro <joecatanzaro@...> writes:

        Joe> But when I run it through ssh, it doesn't return any output. Here are the
        Joe> following variations that I've tried and each time I get nothing.

        The "." command is a shell builtin. If it is accepting redirects,
        those are likely running the command in a subshell, not a shell, and
        you're not getting the right results.

        Try something like:

        ssh user1@box1 -n "(. XXX; . YYY; /home/blah ) 2>&1"

        Note the parens around all three commands.


        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Joe Catanzaro
        ... Randal, Thanks for your response, but I m getting the same results. The fixer program in my example: /home/superuser/fixer/fixer 78758000002063 002 X is a
        Message 3 of 6 , Apr 1, 2004
        • 0 Attachment
          At 4/1/2004 11:05 AM Thursday, merlyn@... wrote:
          >Try something like:
          >
          >ssh user1@box1 -n "(. XXX; . YYY; /home/blah ) 2>&1"

          Randal,

          Thanks for your response, but I'm getting the same results. The fixer
          program in my example:

          /home/superuser/fixer/fixer 78758000002063 002 X

          is a C program. When I attempt to break it in different ways, I get
          different results. Sometimes I'm able to trap my output, but this time I
          get nothing.





          Joe Catanzaro
          joecatanzaro@...
        • merlyn@stonehenge.com
          ... Ahh! What s your shell on the remote box? If it s not /bin/sh (the One True Shell), that syntax doesn t work. I forgot that about ssh. Sorry. -- Randal
          Message 4 of 6 , Apr 1, 2004
          • 0 Attachment
            >>>>> "Joe" == Joe Catanzaro <joecatanzaro@...> writes:

            Joe> At 4/1/2004 11:05 AM Thursday, merlyn@... wrote:
            >> Try something like:
            >>
            >> ssh user1@box1 -n "(. XXX; . YYY; /home/blah ) 2>&1"

            Ahh! What's your shell on the remote box? If it's not /bin/sh
            (the One True Shell), that syntax doesn't work.

            I forgot that about ssh. Sorry.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
          • Joe Catanzaro
            ... user1 echo $SHELL /usr/bin/ksh and that s being set in the first command that s listed in my ssh string when I execute .profile. So, my first thought is
            Message 5 of 6 , Apr 1, 2004
            • 0 Attachment
              At 4/1/2004 11:50 AM Thursday, merlyn@... wrote:
              >Ahh! What's your shell on the remote box? If it's not /bin/sh
              >(the One True Shell), that syntax doesn't work.

              user1 > echo $SHELL
              /usr/bin/ksh

              and that's being set in the first command that's listed in my ssh string
              when I execute .profile. So, my first thought is to add something
              like export SHELL=/usr/bin/sh but that doesn't make sense. What do
              you suggest?


              Joe Catanzaro
              joecatanzaro@...
            • Joe Catanzaro
              My problem was eventually tipped off by Tom of the Omaha Linux User Group with the following post: To: Omaha Linux User Group Subject: Re:
              Message 6 of 6 , Apr 1, 2004
              • 0 Attachment
                My problem was eventually tipped off by Tom of the Omaha Linux User Group
                with the following post:

                To: Omaha Linux User Group <olug@...>
                Subject: Re: [olug] Trapping Strange Output

                Some applications will not write to stdout, but to /dev/tty. Perhaps you
                need to
                use the -t option on ssh.

                Tom Roehr

                And here's the man page listing:

                -t Force pseudo-tty allocation. This can be used to execute arbiĀ­
                trary screen-based programs on a remote machine, which can be
                very useful, e.g., when implementing menu services. Multiple -t
                options force tty allocation, even if ssh has no local tty.

                Thanks again everyone.

                At 4/1/2004 12:07 PM Thursday, Joe Catanzaro wrote:
                >At 4/1/2004 11:50 AM Thursday, merlyn@... wrote:
                > >Ahh! What's your shell on the remote box? If it's not /bin/sh
                > >(the One True Shell), that syntax doesn't work.
                >
                >user1 > echo $SHELL
                >/usr/bin/ksh
                >
                >and that's being set in the first command that's listed in my ssh string
                >when I execute .profile. So, my first thought is to add something
                >like export SHELL=/usr/bin/sh but that doesn't make sense. What do
                >you suggest?


                Joe Catanzaro
                joecatanzaro@...

                [Non-text portions of this message have been removed]
              Your message has been successfully submitted and would be delivered to recipients shortly.