bash script example - ghdrako/doc_snipets GitHub Wiki
Disk usage monitoring
#!/bin/bash
# Define the threshold percentage
THRESHOLD=90
# Get the current disk usage percentage for the root filesystem
CURRENT_USAGE=$(df / | grep / | awk '{print $5}' | sed 's/%//g')
# Check if current usage exceeds the threshold
if [ "$CURRENT_USAGE" -gt "$THRESHOLD" ]; then
echo "Warning: Disk usage has exceeded $THRESHOLD%. Current usage is $CURRENT_USAGE%."
# Send an alert (this can be customized to send an email or other notification)
fi
User Account Check
#!/bin/bash
# Define the number of days of inactivity
DAYS_INACTIVE=30
# Find and list user accounts with last login older than the specified number of days
echo "Listing user accounts inactive for more than $DAYS_INACTIVE days..."
# List users who have not logged in for more than DAYS_INACTIVE days
lastlog -b "$DAYS_INACTIVE"
#!/bin/bash
# Define the URL to get the JSON data
url="http://api.example.com/data"
# Fetch the JSON data
json_data=$(curl -s "$url")
# Extract specific fields using jq
name=$(echo "$json_data" | jq -r '.name')
version=$(echo "$json_data" | jq -r '.version')
# Display the extracted fields
echo "Name: $name"
echo "Version: $version"