Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


remote cpu via telnet

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
claquetteman



Joined: 03 Jul 2003
Posts: 13
Location: France

PostPosted: Tue May 18, 2004 7:43 am    Post subject: remote cpu via telnet Reply with quote

Hi,
I have 5 AIX to supervise, i need to know cpu, but i must not write any file on the AIX systems, there are no oid about processor or cpu load, plus i have been forbidden to install net-snmp or another softwares.
So i use telnet. I would like to know if the scripts are convenable.

There are 2 files in the usr/local/apache/htdocs/cacti/scripts/remotecpu directory.
file cpu_req.php

Code:
 

<?php

$ip=$argv[1];
$login=$argv[2];
$passwd=$argv[3];
$path_list="/usr/local/apache/htdocs/cacti/scripts/remotecpu/list";
$path_listcpu="/usr/local/apache/htdocs/cacti/scripts/remotecpu/listcpu";

function getcpu($ip, $login, $passwd, $path_list)
{
       exec("sh remotecpu.sh $ip $login $passwd > $path_list ");
}

function cleanlist($path_list, $path_listcpu)
{
       exec("more $path_list | sed /[A-Z]/d | sed -e '/[0-9]/!d' > $path_listcpu");
}

function sumcpu($path_listcpu)
{
      static $sum = 0;
      $fp = fopen($path_listcpu, "r");
      whiles(!feof($fp))
      {
             $sum += fgets($fp, 4096);
      }
      fclose($fp);
      print $sum;
}

getcpu($ip, $login, $passwd, $path_list);
cleanlist($path_list, $path_listcpu);
sumcpu($path_listcpu);

?>
 


file remotecpu.sh

Code:
 

#! /bin/sh

(sleep 2
echo "$2"; sleep 5
echo "$3"; sleep 5
echo "ps gu | tr -s ' ' | sed -e 's/[ ]/:/g' | cut -d: -f3 | sed /0.0/d | sed /[Aa-Zz]/d"; sleep 5
echo "exit") | telnet "$1"

#korn shell ksh
# ps gu | tr -s ' ' | sed -e 's/[ ]/:/g' | cut -d: -f3 | sed /0.0/d | sed /[Aa-Zz]/d
#Bourne shell
# ps -aux | tr -s ' ' | sed -e "s/[ ]/:/g" | cut -d: -f3 | sed /0.0/d | sed /[A-Z]/d
 


Code:
 
php cpu_req.php ip login passwd


You need a telnet server on the remote system.

I have a problem because of the time (sleep).
Does someone know how to make a telnet command in a script whithout sleep command?
If the remote system are busy or if the telnet server is down, the request will fail.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group