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

RE: [PBML] failed tty get

Expand Messages
  • Charles K. Clarkson
    ... Does it barf from the command line or only from cron? ... [snip] ... That s busy command. Have you tried it from the command line? Does it perform alright
    Message 1 of 4 , Feb 24, 2003
      Ray Brannam <raybo@...> wrote:

      : I am trying to collect the output from top and take action
      : based on the load of the machine, the script works fine if
      : I run it by hand, but when I run it from cron it always
      : barfs with "top: failed tty get".

      Does it barf from the command line or only from cron?

      : Here is an excerpt from the script:
      [snip]

      : @program="/usr/bin/top -sn 1 | /bin/head -1 | /usr/bin/awk
      : \'{print \$12}\' | /usr/bin/awk -F, \'{print \$1}\'";
      : open(PH, "@program |")|| die "Top is unavailable!\n";

      That's busy command. Have you tried it from the
      command line? Does it perform alright in smaller
      separate pieces? I don't know awk, but can't you
      reproduce that functionality in perl and avoid some
      of that piping?

      BTW, this line would be better written as a scalar
      assignment unless you're using @program for something
      else.

      $program = "...;
      open(PH, "$program |") || ...;

      What does the output of "/usr/bin/top -sn 1 | /bin/head -1"
      look like? Can the whole thing be run from "system"
      instead?

      HTH,

      Charles K. Clarkson
      --
      Head Bottle Washer,
      Clarkson Energy Homes, Inc.
      Mobile Home Specialists
      254 968-8328
    • Nathan.Jeffrey@dhs.vic.gov.au
      Top, from memory, likes to have an interactive terminal behind it, or it does things like that :-) What OS are you using? If Linux, you can probably get the
      Message 2 of 4 , Feb 24, 2003
        Top, from memory, likes to have an interactive terminal behind it, or it
        does things like that :-)

        What OS are you using? If Linux, you can probably get the same info from
        the /proc filesystem with a lot less grief. Other operating systems have
        different ways. I might be able to help, if you can give me more info.

        N





        "Ray Brannam <raybo@...>" <raybo
        24/02/2003 01:47 PM
        Please respond to perl-beginner


        To: perl-beginner@yahoogroups.com
        cc:
        Subject: [PBML] failed tty get


        I am trying to collect the output from top and take action based on
        the load of the machine, the script works fine if I run it by hand,
        but when I run it from cron it always barfs with "top: failed tty
        get".

        Here is an excerpt from the script:
        ----cut----
        #!/bin/perl -w
        #
        # Load Checker.
        #

        use strict;
        use Mail::Sendmail;
        use IO::File;
        use IO::Handle;
        use Time::Local;
        use vars qw($load %mail $limit $debug $io @program $Version);

        # Set the load limit.
        $Version="Version 1.2\n";
        $load=0;
        $limit=4;
        $debug=1;


        # Main routine.
        &main();
        sub main{
        &open;
        &getLoad();
        if ($load >= $limit){
        &restart;
        &mailme;
        } else {
        $io->print("No reason to restart\n");
        }
        undef $io;

        }

        # Get the load level.
        sub getLoad{
        my $load_T=0;
        @program="/usr/bin/top -sn 1 | /bin/head -1 | /usr/bin/awk
        \'{print \$12}\' | /usr/bin/awk -F, \'{print \$1}\'";
        open(PH, "@program |")|| die "Top is unavailable!\n";
        PH->autoflush(1);
        chomp($load_T=<PH>);
        $load=scalar($load_T);
        if ($load eq ""){
        $load=1;
        }
        if ($debug == 1){
        $io->print("Load is: $load\n");
        }
        close PH;
        }
        ----cut----

        Thanks,
        Ray




        Unsubscribing info is here:
        http://help.yahoo.com/help/us/groups/groups-32.html

        Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/







        _________________________________________________________________________________

        This email contains confidential information intended only for the person named above and may be subject to legal privilege. If you are not the intended recipient, any disclosure, copying or use of this information is prohibited. The Department provides no guarantee that this communication is free of virus or that it has not been intercepted or interfered with. If you have received this email in error or have any other concerns regarding its transmission, please notify Postmaster@...
        _________________________________________________________________________________
      • Ray Brannam <raybo@jp.real.com>
        Thank you that was the problem. I started collecting the information from the proc filesystem instead of top and now it works just fine. --Ray ... or it ...
        Message 3 of 4 , Feb 24, 2003
          Thank you that was the problem. I started collecting the information
          from the proc filesystem instead of top and now it works just fine.


          --Ray


          --- In perl-beginner@yahoogroups.com, Nathan.Jeffrey@d... wrote:
          > Top, from memory, likes to have an interactive terminal behind it,
          or it
          > does things like that :-)
          >
          > What OS are you using? If Linux, you can probably get the same
          info from
          > the /proc filesystem with a lot less grief. Other operating
          systems have
          > different ways. I might be able to help, if you can give me more
          info.
          >
          > N
          >
          >
          >
          >
          >
          > "Ray Brannam <raybo@j...>" <raybo
          > 24/02/2003 01:47 PM
          > Please respond to perl-beginner
          >
          >
          > To: perl-beginner@yahoogroups.com
          > cc:
          > Subject: [PBML] failed tty get
          >
          >
          > I am trying to collect the output from top and take action based on
          > the load of the machine, the script works fine if I run it by hand,
          > but when I run it from cron it always barfs with "top: failed tty
          > get".
          >
          > Here is an excerpt from the script:
          > ----cut----
          > #!/bin/perl -w
          > #
          > # Load Checker.
          > #
          >
          > use strict;
          > use Mail::Sendmail;
          > use IO::File;
          > use IO::Handle;
          > use Time::Local;
          > use vars qw($load %mail $limit $debug $io @program $Version);
          >
          > # Set the load limit.
          > $Version="Version 1.2\n";
          > $load=0;
          > $limit=4;
          > $debug=1;
          >
          >
          > # Main routine.
          > &main();
          > sub main{
          > &open;
          > &getLoad();
          > if ($load >= $limit){
          > &restart;
          > &mailme;
          > } else {
          > $io->print("No reason to restart\n");
          > }
          > undef $io;
          >
          > }
          >
          > # Get the load level.
          > sub getLoad{
          > my $load_T=0;
          > @program="/usr/bin/top -sn 1 | /bin/head -1 | /usr/bin/awk
          > \'{print \$12}\' | /usr/bin/awk -F, \'{print \$1}\'";
          > open(PH, "@program |")|| die "Top is unavailable!\n";
          > PH->autoflush(1);
          > chomp($load_T=<PH>);
          > $load=scalar($load_T);
          > if ($load eq ""){
          > $load=1;
          > }
          > if ($debug == 1){
          > $io->print("Load is: $load\n");
          > }
          > close PH;
          > }
          > ----cut----
          >
          > Thanks,
          > Ray
          >
          >
          >
          >
          > Unsubscribing info is here:
          > http://help.yahoo.com/help/us/groups/groups-32.html
          >
          > Your use of Yahoo! Groups is subject to
          http://docs.yahoo.com/info/terms/
          >
          >
          >
          >
          >
          >
          >
          >
          ______________________________________________________________________
          ___________
          >
          > This email contains confidential information intended only for the
          person named above and may be subject to legal privilege. If you are
          not the intended recipient, any disclosure, copying or use of this
          information is prohibited. The Department provides no guarantee that
          this communication is free of virus or that it has not been
          intercepted or interfered with. If you have received this email in
          error or have any other concerns regarding its transmission, please
          notify Postmaster@d...
          >
          ______________________________________________________________________
          ___________
        Your message has been successfully submitted and would be delivered to recipients shortly.