From the course: Linux System Engineer: Bash Shell Scripting for Automation

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Monitoring user space usage

Monitoring user space usage

From the course: Linux System Engineer: Bash Shell Scripting for Automation

Start my 1-month free trial

Monitoring user space usage

- [Instructor] Let's take a look at a real world solution to a problem. In this scenario, we need to keep an eye on disk usage for users. If a user starts using too much disk space, our script will email the system administrator. First we set the limit in bytes. For our test we're going to set it to 100 thousand. Next we assign the directory we want to monitor to the variable MDIR. Then we set up the mailto address. This is where the email will be sent. Then we set an email subject of slash home space disk space usage. Now we have an if conditional. We need to make sure the mailx program is installed. We use the which command to check. If it's not installed, it echos please install mailx and exits. Now our script changes to the slash home directory which is stored in the MDIR variable. Now we loop through all directories on slash home which will be the users home directories. For each directory, we execute d-u space dash s and then use awk to grab the first field which will be the…

Contents