Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • compile_inv.sql Oracle
  • Ports used by Oracle Software Oracle
  • Adding addidional hard drive and attach it to a linux box. Linux/Unix
  • .profile Linux/Unix
  • SQL Server: How to see historical transactions SQL Server
  • Day to day MYSQL DBA operations (Compared with Oracle DBA) MYSQL
  • xargs use Linux/Unix
  • sqlnet.ora paramters Oracle
  • OEM-Commnds Oracle
  • Paste command syntax Linux/Unix
  • Python class import from different folders Python/PySpark
  • Giving Grant on v$DATABASE Oracle
  • setting prompt display with .profile Linux/Unix
  • How do I get Oracle to automatically start when my server boots up? Oracle
  • ext#.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

  • default permission on ~/.ssh/authorized_keys2 or authorized_keys Linux/Unix
  • For Search and replace unix command. Linux/Unix
  • fuser to check who is using diretory Linux/Unix
  • Check_recovery.sh program to run sqlplus and return its values remotely. Linux/Unix
  • scripts to take listener.log backup Linux/Unix
  • Removing first line 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 (400)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (18)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (348)
  • SQL Server (6)
  • Uncategorized (3)
  • Videos (0)

Recent Posts

  • Running PDB on single node in RAC09-Apr-2026
  • find_arc.sql09-Apr-2026
  • pvm_pre_change.sql08-Apr-2026
  • find_encr_wallet.sql08-Apr-2026
  • find_pdbs.sql08-Apr-2026
  • Creating a Container Database using dbaascli08-Apr-2026
  • track_autoupgrade_copy_progress.sql01-Apr-2026
  • refre.sql for multitenant01-Apr-2026
  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Privilege to describe the table. Oracle
  • Find nth max and min. Oracle
  • DBMS_STATS Metalinks Notes Oracle
  • Flowers Resize datafiles Oracle
  • Privileges Required to Create Procedures and Functions that uses objects from other schema. Oracle
  • 10g RAC: Troubleshooting CRS Root.sh Problems Oracle
  • chk_space_SID.ksh Linux/Unix
  • create database syntax Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme