seenu18 has asked for the wisdom of the Perl Monks concerning the following question:
Hi I'm asked to write a sample script for the following scenario
PROCEDURE
Step 1: Login to the node using SSH or Telnet.
Step 2: Execute the below command
i. Show process cpu | grep Total à get the 5s time value
[local]st-tb3-ssr1#show process cpustats | grep Total Total system CPU % usage (5s, 1m, 5m): 7.44, 8.13, 8.64
Note: Total CPU utilization is based on an average of all the cores.
ii. Show memory -> get the Total, Used, Free
[local]st-tb3-ssr1#show memory Memory: Total 24555360k, Used 1679228k, Free 22876132k, Reserved 0k
iii. Show process -> get the process name, CPU % and memory
[local]st-tb3-ssr1#show process Load Average : 0.92 0.88 0.93 NAME PID SPAWN MEMORY TIME %CPU STATE UP/DOWN pakio-protect 3905 1 7328K 00:04:50.10 1.17% run u2l 3568 1 4680K 00:00:00.84 0.00% run 09:47:01 metad 3569 1 34760K 00:00:02.24 0.00% run 09:47:01 evtmd 3605 1 5624K 00:00:04.67 0.02% run 09:46:51 pnsd 3609 1 5764K 00:00:03.42 0.01% run 09:46:51
iv. Show process card # -> get the process name, cpu % and memory
[local]st-tb3-ssr1#show process card 2 -------------------------------------------------------------- Slot number : 2/LP Card Type : 10ge-10-port Load Average : 0.55 0.78 0.89 NAME PID SPAWN MEMORY TIME %CPU STATE UP/DOWN ns 1530 1 4636K 00:01:06.91 0.15% run 09:42:23
Step 3: Wait for the interval (60s) and go in an infinite loop
OUTPUT
1. File name : CPU_Utilization_<NodeIP>_<Date>_<Time> à This file will have the format as below
Time Cpu Utilization 11.5 1.10% 11.55 1.10%
2. File name : MEMORY_Utilization_<NodeIP>_<Date>_<Time> à This file will have the format as below
Time Total Memory
I've scripted the login part so far
#!/usr/bin/perl use strict; use warnings; #use Net::OpenSSH; use Net::Telnet; my $hostname = 'xx.xxx.xxx.xxx'; my $hostname = 'xxxx: my $username = 'xxxx'; my $password = 'xxxx'; my $telnet = new Net::Telnet ( Timeout=>60,Errmode=>'die'); $telnet->open($hostname); print "Telnet Successful\n"; $telnet->waitfor('/login: $/i'); $telnet->print($username); print "Username entered\n"; $telnet->waitfor('/Password: $/i'); $telnet->print($password); print "Password entered\n"; $telnet->waitfor('/\[local\]xx\xxxx\xxxx\xxxx\> $/i'); print "Enable prompt\n"; $telnet->print('enable'); $telnet->waitfor('/Password: $/i'); print "CLI prompt\n"; $telnet->print($password); $telnet->waitfor('/\[local\]xx\xxxx\xxxx\xxxx\# $/i'); my @var1 = $telnet->print(" $telnet->close; print "Telnet session closed\n";
I need help with issuing commands and storing them in the file in the above specified format. At least help me with one show command and storing it's output in a file in the above specified format which is (I'm repeating here again).
h. File name : MEMORY_Utilization_<NodeIP>_<Date>_<Time> à This file will have the format as below
Time Total Memory
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with a grep script
by roboticus (Chancellor) on Nov 08, 2013 at 11:32 UTC | |
|
Re: Need help with a grep script
by kschwab (Vicar) on Nov 08, 2013 at 14:39 UTC | |
by FloydATC (Deacon) on Nov 08, 2013 at 16:26 UTC | |
by kschwab (Vicar) on Nov 08, 2013 at 16:47 UTC | |
|
Re: Need help with a grep script
by ww (Archbishop) on Nov 08, 2013 at 13:37 UTC |