Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Free conference number from http://www.freeconference.com Oracle
  • Find average Row Length and other table size calculation. metalink notes Oracle
  • sql_plan9i.sql Oracle
  • Jai Shree Ram PHP/MYSQL/Wordpress
  • dbms_job.submit example Oracle
  • OEM-troubleshooting on 20-MAY-08 Oracle
  • Clean up Oracle
  • TABLE SIZING WITH DB_BLOCK ARCHITECTURE Reference : Metalink note : 10640.1 Oracle
  • Oracle Material from OTN Oracle
  • plan10g.sql good Oracle
  • longtx.sql Oracle
  • Find_table_size.sql Oracle
  • S3 Basic info AWS
  • Jai Shree Ram Linux/Unix
  • pvm_pre_change.sql Oracle

How to collect CPU usage on Linux using Shell script

Posted on 09-Jun-202309-Jun-2023 By Admin No Comments on How to collect CPU usage on Linux using Shell script

Following script will help to collect CPU based on on every SAMPLE_TIME. This will help to collect IDLE CPU our from “vmstat” and store them in a file.

#Setup SAMPLE_TIME for cpu data collection interval
SAMPLE_TIME=5
while true
do
x=`vmstat | grep -v procs | grep -v swpd | awk '{print $15}'`
echo `date +"%m-%d-%y %T"` $x
sleep ${SAMPLE_TIME}
done

Create file with above contents and save it as test_cpu.sh for example. 

Now, to run this collection in background use the following command.

nohup ./test_cpu.sh 1>test_cpu.out 2>&1 &

you can monitor using “tail -f test_cpu.out” for incremental progress of data collection. You can also use any visual tool like power BI or Excel for quick analysis. 

Linux/Unix, shell

Post navigation

Previous Post: Move WordPress site from one hosting service to other.
Next Post: Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle

Related Posts

  • restarting network in linux Linux/Unix
  • replace alphabets using sed Linux/Unix
  • .profile Linux/Unix
  • rm_backup_arch_file.ksh Linux/Unix
  • Adding addidional hard drive and attach it to a linux box. Linux/Unix
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (392)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • load SPM baseline from cursor cache05-Jun-2025
  • Drop all SPM baselines for SQL handle05-Jun-2025
  • Load SPM baseline from AWR05-Jun-2025
  • Drop specific SQL plan baseline – spm05-Jun-2025
  • findinfo.sql (SQL for getting CPU and Active session info)27-May-2025
  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Jai Shree Ram Oracle
  • block_ident.sql Oracle
  • DBA_HIST_SQLSTAT contents Oracle
  • Running some SQL on multiple databases connecting using monitoring userid and password Linux/Unix
  • Renaming the column name Oracle
  • Adding a new disk and mount it automatically. on VMWARE LINUX Linux/Unix
  • Order by with ROWNUM Oracle
  • Virtual Indexes in Oracle Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme