top of page

Linux Project - Monitor Server Disk Space

Build a script to monitor and report server disk usage.

In this Linux project we will write a shell script that will monitor the disk space and put the info in a file every 20 mints.




Setting up Oracle Linux 7 on Virtual Box


Follow these detailed steps for the exact process we consistently use to create a virtual machine (VM) and practice Oracle on Oracle VirtualBox. Step-by-Step Guide: Setting Up Oracle Linux 7 on Oracle VirtualBox



How to Find Disk Free Space?


We use the below command to find the disk free space on Linux

df -h


Script to Log Disk Space


Creating a script to log disk space simplifies monitoring and helps manage storage effectively, ensuring timely updates on disk utilization.


  • Create Scripts Folder: to store and organise various scripts

mkdir /tmp/scripts
  • Storage Space log: This file will store storage information

touch /tmp/scripts/storage_space.log
  • Permission for Log File:

chmod 777 /tmp/scripts/storage_space.log

Shell script executing 'df -h' to retrieve and log free disk space information, saving results in storage_space.log with timestamps for each entry

#! /bin/bash
	
# To find the free disk space and save it in a log file
	echo "********************************************" >> /tmp/scripts/storage_space.log
	date >> /tmp/scripts/storage_space.log
	echo "********************************************" >> /tmp/scripts/storage_space.log
	df -h >> /tmp/scripts/storage_space.log

# To insert a space between each log entry
	echo >> /tmp/scripts/storage_space.log

Permission for Shell Script:

chmod 777 /tmp/scripts/get_storage.sh


Schedule Script via crontab


Creation of crontab: Automate script execution at 20-minute intervals

crontab -e
*/20 * * * * /tmp/scripts/get_storage.sh

Become a top notch dba with DBA Genesis
Start your DBA career today
bottom of page