Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Vivek Tuning for Row Locks. Oracle
  • Renaming Oracle Instance Name Oracle
  • Generating XML from SQLPLUS Oracle
  • get_vmstat.ksh for Solaris Oracle
  • Jai Shree Ram Linux/Unix
  • DBMS_UTILITY.ANALYZE_SCHEMA Oracle
  • OPENING A STANDBY DATABASE IN READ-ONLY MODE Oracle
  • SQL Server: How to see historical transactions SQL Server
  • Export Oracle data and Compress at same time Oracle
  • How To Resolve Stranded DBA_2PC_PENDING Entries ID 401302.1 (Very Good prooven) Oracle
  • standard Monitoring – 1 Oracle
  • Very Good Oralce Internal Tuning Book Oracle
  • Default User Profile Oracle
  • SAT Mathematics 10 questions and answer at the end. Uncategorized
  • To see only files and/or folders using LS command Linux/Unix

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

  • adding new line after specific pattern using sed Linux/Unix
  • How to remove blank lines using vi editor command Linux/Unix
  • How does one overcome the Unix 2 Gig file limit? Linux/Unix
  • chk_space_SID.ksh Linux/Unix
  • Check_recovery.sh program to run sqlplus and return its values remotely. Linux/Unix
  • To Find Orphan OS processes. Linux/Unix

Leave a Reply Cancel reply

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

Categories

  • AMC10 (0)
  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (150)
  • MYSQL (5)
  • Oracle (403)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (18)
  • rman-dataguard (26)
  • shell (151)
  • SQL scripts (349)
  • SQL Server (6)
  • Uncategorized (9)
  • Videos (0)

Recent Posts

  • Tutornet.US — Source of excellent learning14-Oct-2026
  • OCI Infrastructure Patching14-Oct-2026
  • Free API credits for AI models14-Oct-2026
  • AMC1020-Sep-2026
  • Key Management in Oracle: The Core Issue: Missing Master Key12-May-2026
  • SAT Mathematics 10 questions and answer at the end.30-Apr-2026
  • top 10 AI news today30-Apr-2026
  • runon_allpdbs_show_conname.sh23-Apr-2026
  • runon_allcdbs_find_pdbs.sh23-Apr-2026
  • Running PDB on single node in RAC09-Apr-2026

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • move_arch_files.ksh /* Good One */ Linux/Unix
  • usnsql.sql Displays information about UNDO segments with sql statements Oracle
  • Adding a new disk and mount it automatically. on VMWARE LINUX Linux/Unix
  • find_arc.sql Oracle
  • DBA_HIST_SQLSTAT contents Oracle
  • To check whether standby is recovering properly or not?? Oracle
  • scripts to take listener.log backup Linux/Unix

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme