Sponsored Content
Top Forums Shell Programming and Scripting Help with Shell script that monitors CPU Usage Post 303028222 by mhannor on Wednesday 2nd of January 2019 09:07:41 AM
Old 01-02-2019
Help with Shell script that monitors CPU Usage

I'm a newbie to shell scripting, I was given this script to modify. This script that monitors when CPU Usage is too high based off the top command. The comparison is not working as it should. Its comparing a decimal to a regualar interger. When it send me an email, it send an email and ignores the if statement. I receive an email if its below or above 90. I only need an email if its greater than 90. I use
Code:
 while :; do :; done

to run CPU up to 100%. and then test running the below script. Can you all please assist me in what I'm doing incorrectly here:

Code:
#!/bin/ksh
top -b -n 1 |head -8 >/tmp/cpu.text
sed -e '1,5d' /tmp/cpu.text >/tmp/cpu2.text
High_CPU=`cat /tmp/cpu2.text|tail -1|awk '{print $9}'`
host=`hostname`
if [ "$High_CPU -gt  90" ];
then
mail -s "High CPU USAGE on $host" test@test.comv < /tmp/cpu2.lst
fi
exit;

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Shell Programming and Scripting

shell script to alert cpu memory and disk usage help please

Hi all can any one help me to script monitoring CPU load avg when reaches threshold value and disk usage if it exceeds some % tried using awk but when df -h out put is in two different lines awk doesnt work for the particular output in two different line ( output for df -h is in two... (7 Replies)
Discussion started by: robo
7 Replies

5. HP-UX

Perl script limit cpu usage

Hi Experts, I am executing multiple instances(in parallel) of perl script on HP-UX box. OS is allocating substantial amount of CPU to these perl processes,resulting higher cpu utilization. Glance always shows perl processes are occupying majority of the CPU resource. It is causing slower... (2 Replies)
Discussion started by: sai_2507
2 Replies

6. Shell Programming and Scripting

Shell script for logging cpu and memory usage of a Linux process

I am looking for a way to log and graphically display cpu and RAM usage of linux processes over time. Since I couldn't find a simple tool to so (I tried zabbix and munin but installation failed) I started writing a shell script to do so The script file parses the output of top command through... (2 Replies)
Discussion started by: andy_dufresne
2 Replies

7. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

8. Shell Programming and Scripting

CPU usage script

Hello Friends, I am trying to create a shell script which will check the CPU utilization. I use command top to check the %CPU usage. It give s me below output Cpu states: CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0 0.31 9.6% 0.0% 6.1% 84.3% 0.0% 0.0%... (3 Replies)
Discussion started by: Nakul_sh
3 Replies

9. Shell Programming and Scripting

Script for CPU usage -Linux

Hi all I was wondering if its possible to write a script to keep CPU usage at 90%-95%? for a single cpu linux server? I have a perl script I run on servers with multple cpu's and all I do is max all but one cpu to get into the 90'% utilised area. I now need a script that raises the CPU to... (4 Replies)
Discussion started by: sudobash
4 Replies

10. Shell Programming and Scripting

Help with speeding up my working script to take less time - how to use more CPU usage for a script

Hello experts, we have input files with 700K lines each (one generated for every hour). and we need to convert them as below and move them to another directory once. Sample INPUT:- # cat test1 1559205600000,8474,NormalizedPortInfo,PctDiscards,0.0,Interface,BG-CTA-AX1.test.com,Vl111... (7 Replies)
Discussion started by: prvnrk
7 Replies
adt-testreport-onepackage(1)				     Linux Programmer's Manual				      adt-testreport-onepackage(1)

NAME
adt-testreport-onepackage - choose one package and test it with adt-run SYNOPSYS
adt-testreport-onepackage [variable=value|settings-file]... DESCRIPTION
adt-testreport-onepackage is a rather ad-hoc script which chooses a package to test, calls adt-run, and reports the results. In a service installation a-t-o is usually called from adt-testreport-runloop. a-t-o has the following functionality: a-t-o downloads the Sources or Packages file, chooses a package to test (see below), downloads its source, invokes adt-run, writes a report describing the outcome, and emails the report to some appropriate address. WARNING - it is essential to reconfigure this program before use, as the supplied examples will send emails to people who will become very upset with you! CONFIGURATION
Command-line arguments containing = are interpreted by a-t-o with eval; other arguments are sourced using ., in each case interpreted as bash script. Configuration fragment authors should bear in mind that a-t-o uses set -e. Various variables can be set for useful effect. A selection of the most usual ones, with default values, can be seen at the top of the a- t-o script itself. Certain others are mentioned in this manpage. There is no exhaustive list and no documentation of the semantics. PACKAGE AND TEST SELECTION
The configuration variable target specifies whether a source package, or a binary package, is to be tested. It should be set to source or binary-arch. a-t-o maintains a record of when each package was last tested, what version was tested, and whether the package had any tests. This record is used to choose which package should be tested next: packages which have changed since the last test are preferred, as are packages which didn't lack tests last time they were examined. If the configuration sets pkg to a package name (for example if pkg=package is passed as an argument), this overrides a-t-o's package selection algorithm. REPORTING
If interactive is set to true (the default), a-t-o will not redirect the output from adt-run and will not email anyone, although the start of the email which would have been sent is sent to stdout. If interactive is false, a-t-o sends an email to its administrator (if a-t-o considers that the testing machinery is broken, or if maintainer_email_override is set), or otherwise to the package maintainer. No email is sent if there were no tests, or all the tests skipped or passed. The emailed report contains a summary of the outcome of the tests, and the output from adt-run. Additionally, if an email is sent, the build trees, test results, and so forth, will be uploaded to the location specified with the dest* options (see the onepackage-config exam- ple configuration file). Some vague progress information is printed to a-t-o's stdout. AUTOMATIC BUG REPORTING
With suitable configuration, a-t-o can be made to automatically file bugs when it detects a problem with a package. It is necessary to avoid the submission of multiple reports for the same problem. This is done by fetching somehow a list of the open bug reports from the relevant bug system and extracting a list of the source package names. These are to be listed in the file named by the suppresspackages configuration variable. Testing frequency of these source packages is reduced, and when a problem is found the email is not sent. When the system does decide to send an email about a package it will normally email the maintainer as determined from the package's control file. To submit bugs instead, set maintainer_email_override to the submission email address for the bug system. You must also set email_sourcepackage_headerandemail_binarypackage_header to appropriate templates. These templates specify what information should be prepended at the top of the body (not the RFC822 header) of the mail to be sent. In these templates @p stands for the package name being tested (the source package name for source packages or the binary package name for binary package tests), @v stands for the version being tested, @s stands for the source package name (even if a binary package generated by that source is being tested) and @a stands for a sin- gle at sign @. If you an appropriately useable GPG signing key is available, you may specify email_signing_key which is passed to gpg's -u option. Other- wise the email is not signed. FILES
The tmp=tmp and var=var configuration variables name two directories which must belong solely to this instance of a-t-o. tmp will be erased by a-t-o at startup and then used for temporary files. It is not cleaned up afterwards; it is assumed that the next run of a-t-o will do that. tmp should not be made to refer to a symlink or mountpoint as a-t-o would break the link or attempt to remove the mountpoint; specify a subdirectory instead. var is used to record the state, including the information about each package used for package selection. var/log contains a one-line record of each test run and may need to be rotated. tmp and var default to tmp and var in a-t-o's starting directory. EXIT STATUS
0 a package was apparently tested 20 adt-run reported an unexpected failure other other unexpected failures including bad usage, disk full, etc. When a-t-o is run in a loop, the loop should stop pending administrator intervention if a-t-o exits nonzero. FILES
tmp (default: ./tmp) Temporary directory for working files. Do not specify /tmp. var (default: ./var) Storage directory for package testing history, score reports, logfiles, etc. var/lastinfo-target Information about the last test and outcome for each package. This is used for package scoring and selection. var/scores-target Report giving the score for each package, and the factors which influenced that score. var/emailed/last-pkg,emailaddress The summary of the last message sent to emailaddress about pkg. If the configuration variable suppressrepeatedemails is true then this is used to ensure that a maintainer (or the test installation operator) is only emailed when the situation for a particular package changes. var/emailed/diff-pkg Changes to the summary for the last email sent regarding pkg. This can be used to find out why an email was sent. var/log Logfile from a-t-o. If a-t-runloop is being used its stdout output often makes a better logfile. destrsynchead/destdirfin/pkg Full logfile and other information is rsync'd here. It is assumed that this area will be published via a webserver. SEE ALSO
adt-run(1). BUGS
It is essential not to use the example configuration! This configuration is likely to send inappropriate emails! There is no documentation for the variable settings, and no error handling for detecting attempts to set incorrectly named variables. The tuning parameters for the package selection algorithm cannot be adjusted. This algorithm is not hugely sophisticated. There should be a facility for explicitly requesting retests (other than setting pkg); there should be some kind of manual prioritisation queue. Distributions whose management systems permit archive skew (that is, distributions whose contents sometimes contains unsatisfiable depen- dencies) cause pathological behaviour. a-t-o will prefer to test the newly-changed packages and immediately detect and report the archive skew as test failures. It would be better if it would detect this situation and not report a failure unless the problem persisted. And there ought to be an option to have it not try to test a package until its version has been stable for a nominated period. If multiple distributions (multiple values of distro) are used, a-t-o will conflate their last-tested versions. It should use separate files. Cross-architecture testing (where host and target have differing Debian architectures) has not been tested and is likely to have bugs both in interfaces and implementation. a-t-o should be capable of automatically closing bug reports if it retests a package and finds that the bug is fixed. The script lacks flexibility in many respects; many additional configuration settings and hooks are needed. There is no facility for sharing test queues across multiple machines. This means that it is difficult to share the testing load. AUTHORS AND COPYRIGHT
This manpage is part of autopkgtest, a tool for testing Debian binary packages. autopkgtest is Copyright (C) 2006-2007 Canonical Ltd and others. See /usr/share/doc/autopkgtest/CREDITS for the list of contributors and full copying conditions. autopkgtest 2007 adt-testreport-onepackage(1)
All times are GMT -4. The time now is 09:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy