Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • OEM-Commnds Oracle
  • switchlogfile.sh Linux/Unix
  • Oracle10g – Using SQLAccess Advisor (DBMS_ADVISOR) with the Automatic Workload Repository Oracle
  • sid_wise_sql.sql Further explaination Oracle
  • Drop database in Oracle 10g Oracle
  • Handling LOB data in Oracle Oracle
  • nfs mount command Linux/Unix
  • DBMS_Shared_pool pinning triggers Oracle
  • Check SQL Server edition SQL Server
  • Locktree.sql Oracle
  • Remove DOS CR/LFs (^M) Linux/Unix
  • Proc Compilation Oracle
  • Postgres DB user and OS user. POSTGRESQL
  • Formatter Explain plan Output 1 Oracle
  • Read CSV File using Python Python/PySpark

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

  • Deleting first line and lastline of a file using sed Linux/Unix
  • chk_space_SID.ksh Linux/Unix
  • tar and untar a dolder with all its subfolder. Linux/Unix
  • scripts to take listener.log backup Linux/Unix
  • Single character replacement in Unix Linux/Unix
  • How does one SELECT a value from a table into a Unix variable? From SQL to Shell Linux/Unix

Leave a Reply Cancel reply

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

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Complete Git Tutorial for Beginners25-Dec-2025
  • Postgres DB user and OS user.25-Dec-2025
  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Looping for remote servers and find its database from oratab file. Linux/Unix
  • Does DBMS_JOB recompute the NEXT_DATE interval after or before Oracle
  • To seee semaphores and shared memory segments in Solaris Linux/Unix
  • find checksum of a file. Linux/Unix
  • How does one overcome the Unix 2 Gig file limit? Linux/Unix
  • Building Our Own Namespaces with “Create Context” Oracle
  • Directory wise folder wise space usage Linux/Unix
  • For Perl DBI installation and testing program PHP/MYSQL/Wordpress

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme