Sponsored Content
Operating Systems Linux Gentoo cpu%/mem% usage, scripting, dzen2: howto learn bash the hard way Post 302220994 by broli on Saturday 2nd of August 2008 07:29:39 PM
Old 08-02-2008
cpu%/mem% usage, scripting, dzen2: howto learn bash the hard way

I am trying to write a small (and rather simple) script to gather some info about the system and piping it to dzen2

first, i want to explain some things.
I know i could have used conky, but my intention was to expand my knowledge of bash, pipes and redirections inside a script, and to have fun (which i am)
some time later, i also decided to try to be more strict on the resource usage. this is a script that will constantly run on a low-end laptop.

also, dzen is not the important part of the script and can be simple ignored, is just a way to show the info. if you are interested in dzen, you can read more info here gotmor - dzen

so, lets talk about the script itself

i use top in batch mode to get the list of most cpu/mem using, but now, i would like to include the total too. (in percentage)

with the memory, i was thinking maybe using free, and doing some math on the used/cached fields. but that would involve a new app to run, when top already gave me the info.
but taking the info from top's output will require a heavy use of pipes and secondary apps like tail and head

with the cpu%, well, im lost .....
where could i find that info?
im thinking, maybe is better to just use the iddle% field of top

this is what i have done so far
general pastebin - broli - post number 1091305

any suggestion on how to improve what i have done will also be welcomed
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference in Mem usage ?

Hi All, I have a pair of sun ultra 5_10 with SunOS 5.5.1. Both are almost equally patched and set up with simillar applications. host# uname -a SunOS host 5.5.1 Generic_103640-24 sun4u sparc SUNW,Ultra-5_10 Even though both have same amount of RAM ( 512 Mb ) , ... (1 Reply)
Discussion started by: shibz
1 Replies

2. Linux

High Mem & Cpu Utilisation

Hi All, Kindly help me in optimizing the server as it displays a great amount of CPU & MEM being utilised when the mysql process executes. Below are the stats --- -------------------------------------------------------------------------- # top 15:51:57 up 23:22, 5 users, load average:... (1 Reply)
Discussion started by: gautamatul82
1 Replies

3. Linux

Linux Mem Usage

What is amount of free RAM i have now? total used free shared buffers cached Mem: 1010 963 46 0 215 256 -/+ buffers/cache: 491 518 Swap: 1983 0 1983 Above is the output of... (1 Reply)
Discussion started by: new2ss
1 Replies

4. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Shell Programming and Scripting

Help with bash script - Need to get CPU usage as a percentage

I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of... (3 Replies)
Discussion started by: graysky
3 Replies

7. UNIX for Dummies Questions & Answers

HOWTO - Total memory and CPU usage ... without top?

Hi all, Is it possible to get total memory usage and free memory usage without top? By Googling I found for total memory usage, use vmstat, for CPU, use mpstat, for disk I/O use iostat, is this correct? Will using sar gives the same result as ALL of these three (3) commands? What about if I... (2 Replies)
Discussion started by: newbie_01
2 Replies

8. Shell Programming and Scripting

Should I learn bash scripting or is it going obsolete?

Hi folks, I'm a CS students enrolled in a sysadmin class where we've been covering bash scripting for the past few weeks. I have prior knowledge in java, c++, c#, python,and some scripting languages like asp.net w/c# and php. This bash stuff seems pretty neat and a bit different than what I am... (9 Replies)
Discussion started by: KalEl
9 Replies

9. Shell Programming and Scripting

Command to find total cpu and mem

Hi All, I need to know the command for knowing the total cpu and mem. Thanks (5 Replies)
Discussion started by: aish11
5 Replies

10. UNIX for Dummies Questions & Answers

Learn bash shell scripting

I do not know shell scripting. But at work place, I have got an in and out shell scripting task. I just need to understand a very big script. Is there any tool in which I can place the script and it can tell me the meaning of the whole script? (3 Replies)
Discussion started by: lg123
3 Replies
App::Nopaste(3pm)					User Contributed Perl Documentation					 App::Nopaste(3pm)

NAME
App::Nopaste - easy access to any pastebin SYNOPSIS
use App::Nopaste 'nopaste'; my $url = nopaste(q{ perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)1+$/' [number] }); # or on the command line: nopaste test.pl => http://pastebin.com/fcba51f DESCRIPTION
Pastebins (also known as nopaste sites) let you post text, usually code, for public viewing. They're used a lot in IRC channels to show code that would normally be too long to give directly in the channel (hence the name nopaste). Each pastebin is slightly different. When one pastebin goes down (I'm looking at you, <http://paste.husk.org>), then you have to find a new one. And if you usually use a script to publish text, then it's too much hassle. This module aims to smooth out the differences between pastebins, and provides redundancy: if one site doesn't work, it just tries a different one. It's also modular: you only need to put on CPAN a App::Nopaste::Service::Foo module and anyone can begin using it. INTERFACE
CLI See the documentation in App::Nopaste::Command. "nopaste" use App::Nopaste 'nopaste'; my $url = nopaste( text => "Full text to paste (the only mandatory argument)", desc => "A short description of the paste", nick => "Your nickname", lang => "perl", chan => "#moose", private => 1, # default: 0 # this is the default, but maybe you want to do something different error_handler => sub { my ($error, $service) = @_; warn "$service: $error"; }, warn_handler => sub { my ($warning, $service) = @_; warn "$service: $warning"; }, # you may specify the services to use - but you don't have to services => ["Shadowcat", "Gist"], ); print $url if $url; The "nopaste" function will return the URL of the paste on success, or "undef" on failure. For each failure, the "error_handler" argument is invoked with the error message and the service that issued it. For each warning, the "warn_handler" argument is invoked with the warning message and the service that issued it. SEE ALSO
WebService::NoPaste, WWW::Pastebin::PastebinCom::Create, Devel::REPL::Plugin::Nopaste http://perladvent.org/2011/2011-12-14.html <http://perladvent.org/2011/2011-12-14.html> AUTHOR
Shawn M Moore, "sartak@gmail.com" COPYRIGHT AND LICENSE
Copyright 2008-2010 Shawn M Moore. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-12-15 App::Nopaste(3pm)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy