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

In reply to Need help with a grep script by seenu18

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.