Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Index Range Scan Oracle
  • Caching sequence in Memory Oracle
  • tab.sql Oracle
  • Monitor Long Running Job Oracle
  • how to find OS block size Oracle
  • Good RAC & Standby Notes Oracle
  • My Test Case On 21-OCT-2005 Oracle
  • online_ts_bkup.sql Oracle
  • setting prompt display with .profile Linux/Unix
  • Sort with ASCII order and Numeric Order Linux/Unix
  • login.sql Oracle
  • When to rebuld B-tree index Oracle
  • Updated LCK.SQL file. Oracle
  • OPENING A STANDBY DATABASE IN READ-ONLY MODE Oracle
  • Sending SQLPLUS output in HTML format 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

  • crontab syntax Linux/Unix
  • To see only files and/or folders using LS command Linux/Unix
  • replace alphabets using sed Linux/Unix
  • send email from unix mailx with attachment. Linux/Unix
  • telnet listening Linux/Unix
  • Processes parameter and its dependencies on OS kernel parameters 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
  • First Entry in RAC Oracle
  • db_status.sql Oracle
  • SQL_PLAN.sql for checking real execution plan Oracle
  • scp with ssh2 Linux/Unix
  • GSQ.sql Oracle
  • Read CSV File using Python Python/PySpark
  • Pending Distributed Transations Oracle
  • My Minimum Tuning Programs Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme