Write me a script for linux to check disk space and email me if it is over 90% full
user
you can use the following shell script to check the disk space and send an email when the disk usage exceeds 90%. replace the `your_email_address` placeholder with your email address.

before using the script, ensure you have `mail` utility installed on your machine. you can install it using the following command:

```bash
sudo apt-get install mailutils
```

create a file using your preferred text editor (e.g., nano, vim, etc.), and name it "disk_space_check.sh":

```bash
#!/bin/bash

# set the maximum allowed disk usage percentage (threshold)
threshold=90

# provide the email address where to send the alert
email="your_email_address"

# get the current disk usage percentage (excluding the '%' sign)
usage=$(df / | tail -1 | awk '{print $5}' | sed 's/%//g')

# check if the usage is greater than or equal to the threshold
if [ "$usage" -ge "$threshold" ]; then
    # create the email subject and body
    subject="disk space alert: $(hostname) - $(date)"
    body="warning! disk usage on $(hostname) has reached $usage%. the threshold is set at $threshold%."

    # send the email
    echo "$body" | mail -s "$subject" "$email"
fi
```

save the file and make the script executable:

```bash
chmod +x disk_space_check.sh
```

you can run the script manually or schedule it to run periodically using a cron job. to schedule a cron job, run `crontab -e` and add the following line to run the script daily at 12:00 pm (customize the time as needed):

```cron
0 12 * * * /path/to/disk_space_check.sh
```

replace `/path/to/` with the actual path to the script. save the file, and the cron job will be configured to run the script at the specified time.
assistant
You can use the following shell script to check the disk space and send an email when the disk usage exceeds 90%. Replace the `YOUR_EMAIL_ADDRESS` placeholder with your email address.

Before using the script, ensure you have `mail` utility installed on your machine. You can install it using the following command:

```bash
sudo apt-get install mailutils
```

Create a file using your preferred text editor (e.g., nano, vim, etc.), and name it "disk_space_check.sh":

```bash
#!/bin/bash

# Set the maximum allowed disk usage percentage (Threshold)
THRESHOLD=90

# Provide the email address where to send the alert
EMAIL="YOUR_EMAIL_ADDRESS"

# Get the current disk usage percentage (excluding the '%' sign)
USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//g')

# Check if the usage is greater than or equal to the threshold
if [ "$USAGE" -ge "$THRESHOLD" ]; then
    # Create the email subject and body
    SUBJECT="Disk Space Alert: $(hostname) - $(date)"
    BODY="Warning! Disk usage on $(hostname) has reached $USAGE%. The threshold is set at $THRESHOLD%."

    # Send the email
    echo "$BODY" | mail -s "$SUBJECT" "$EMAIL"
fi
```

Save the file and make the script executable:

```bash
chmod +x disk_space_check.sh
```

You can run the script manually or schedule it to run periodically using a cron job. To schedule a cron job, run `crontab -e` and add the following line to run the script daily at 12:00 PM (customize the time as needed):

```cron
0 12 * * * /path/to/disk_space_check.sh
```

Replace `/path/to/` with the actual path to the script. Save the file, and the cron job will be configured to run the script at the specified time.
assistant