Check disk space on CloudTest servers

Check disk space on CloudTest servers

To determine your root drive usage, you can run the following command, which will return the usage percentage:

df -h | head -n 3 | tail -n 1 | awk '{print $4}'

To get the usage percentage of the data folder which is usually the last drive to show up using the df command:

df -h | tail -n 1 | awk '{print $5}'

You can then capture this percentage and use if statement to send email to the admin using sendmail command.

The script in Check disk space on CloudTest servers will implement the code above, to use run:

check_diskspace.sh [Maximum Percentage] [admin email]

For example to send alerts if the disk usage is above 80%:

check_diskspace.sh 80 admin@email.com