Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • move_arch_files.ksh Linux/Unix
  • Removing first line Linux/Unix
  • TABLE SIZING WITH DB_BLOCK ARCHITECTURE Reference : Metalink note : 10640.1 Oracle
  • To Find Orphan OS processes. Linux/Unix
  • online_bkup.sql Oracle
  • 276434.1 Modifying the VIP or VIP Hostname of a 10g or 11g Oracle Clusterware Node Oracle
  • Roles and Stored Object behaviour Oracle
  • SQLPLUS COPY command Precautions. Oracle
  • All Hints for Oracle Databases Oracle
  • Oracle Material from OTN Oracle
  • RMAN : Consistent Backup, Restore and Recovery using RMAN Oracle
  • Composite Index creation tip from Vivek Oracle
  • Passing from Unix to PLSQL using bind variables Linux/Unix
  • How to stop OCSSD Daemon Oracle
  • find_idle_cpu.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

  • Korn Shell Arithmatic Linux/Unix
  • cold backup scripts to copy locally Linux/Unix
  • send email from unix mailx with attachment. Linux/Unix
  • How to remove blank lines using vi editor command Linux/Unix
  • Search and Replace vi editor command. Linux/Unix
  • How does one overcome the Unix 2 Gig file limit? 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
  • Kill a session dynanically using execute immediate Oracle
  • 10g RAC: Troubleshooting CRS Root.sh Problems Oracle
  • mutex in Oracle 10.2.0.2 or Oracle 10g Oracle
  • How can I tell if ASO is installed ? Oracle
  • exp syntax in oracle 10g Oracle
  • Read CSV File using Python Python/PySpark
  • normal maintenance for exp-imp and renaming table Oracle
  • process id based files and processes Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme