top of page

Linux Project - Monitor Server Disk Space

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/

Schedule Script via crontab

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

crontab -e
*/20 * * * * /tmp/scripts/

Related Posts

Heading 2

Add paragraph text. Click “Edit Text” to customize this theme across your site. You can update and reuse text themes.

bottom of page