Book Image

CentOS 7 Linux Server Cookbook - Second Edition

By : Jonathan Hobson
Book Image

CentOS 7 Linux Server Cookbook - Second Edition

By: Jonathan Hobson

Overview of this book

This book will provide you with a comprehensive series of starting points that will give you direct access to the inner workings of the latest CentOS version 7 and help you trim the learning curve to master your server. You will begin with the installation and basic configuration of CentOS 7, followed by learning how to manage your system, services and software packages. You will then gain an understanding of how to administer the file system, secure access to your server and configure various resource sharing services such as file, printer and DHCP servers across your network. Further on, we cover advanced topics such as FTP services, building your own DNS server, running database servers, and providing mail and web services. Finally, you will get a deep understanding of SELinux and you will learn how to work with Docker operating-system virtualization and how to monitor your IT infrastructure with Nagios. By the end of this book, you will have a fair understanding of all the aspects of configuring, implementing and administering CentOS 7 Linux server and how to put it in control.
Table of Contents (22 chapters)
CentOS 7 Linux Server Cookbook Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Monitoring important server infrastructure


In this recipe, we will use a small script that will monitor the available filesystem's disk space periodically using cron, and if it exceeds a certain percentage threshold the script will send out a mail with a warning message.

Getting ready

To complete this recipe, you will require a working installation of the CentOS 7 operating system with root privileges and a console-based text editor of your choice. You should have read the Scheduling tasks with cron recipe to have a basic understanding of the principles behind the cron system.

How to do it...

  1. To begin this recipe, log in as root and create the following file that will contain our monitoring script:

    vi /etc/cron.daily/monitor_disk_space.sh
    
  2. Now, put in the following content:

    #!/bin/bash
    EMAIL="root@localhost"
    THRESHOLD=70
    df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
    do
      usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
      partition=$(echo...