Introduction
In enterprise environments, admins require a consolidated script that executes multiple Nutanix operational tasks safely and consistently. This article presents a production-grade “super script” that consolidates health checks, VM inventory, snapshot rotation, and alert generation, suited for daily use in mission-critical deployments.
My Personal Repository on GitHub
Diagram: Super Script Flow
Script Design Goals
- Modular: Easy to add/remove functions
- Logged: Full audit trail
- Alerting: On failures, warnings, or anomalies
- Secure: Handles credentials and outputs responsibly
- Maintainable: Uses functions, configs, and safe patterns
Super Bash Script: nutanix_ops_master.sh
#!/usr/bin/env bash
set -euo pipefail
log="/var/log/nutanix_ops_$(date +%F).log"
warn_days=30
host="ntx-prism.example.com"
report_recipient="ops@example.com"
header() { echo "========== $1 =========="; }
cluster_health_check() {
header "CLUSTER HEALTH"
ncli cluster get-health
}
vm_inventory_report() {
header "VM INVENTORY"
ncli vm list | grep -E "Name|Power State"
}
snapshot_rotation() {
header "SNAPSHOT ROTATION"
vms=("web01" "db01")
for vm in "${vms[@]}"; do
snap_name="${vm}_snap_$(date +%Y%m%d)"
acli vm.snapshot_create "$vm" snapshot_name="$snap_name"
snaps=$(acli vm.snapshot_list "$vm" | awk 'NR>2 {print $1}' | sort)
[[ $(echo "$snaps" | wc -l) -gt 3 ]] && {
echo "$snaps" | head -n -3 | while read old; do
acli vm.snapshot_delete "$vm" snapshot_name="$old"
done
}
done
}
cert_expiry_check() {
header "CERTIFICATE EXPIRY"
expiry_date=$(echo | openssl s_client -connect "${host}:9440" -servername "$host" 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
days_left=$(( ( $(date -d "$expiry_date" +%s) - $(date +%s) ) / 86400 ))
echo "Cert expires in $days_left days"
(( days_left < warn_days )) && echo "⚠️ Certificate expiring soon!"
}
main() {
{
echo "Nutanix Daily Enterprise Ops Report - $(date)"
cluster_health_check
vm_inventory_report
snapshot_rotation
cert_expiry_check
} >> "$log" 2>&1
mailx -s "Nutanix Ops Dashboard $(date +%F)" "$report_recipient" < "$log"
}
main
Scheduling in Production
0 6 * * * /usr/local/bin/nutanix_ops_master.sh
Executes daily at 6:00 AM and emails the consolidated report to the ops team.
Customization Options
- Include VM memory and disk stats
- Add backup status from
ncli - Push metrics to Prometheus or Splunk
- Pull data from multiple clusters in loop
Summary
This all-in-one Nutanix script brings together critical operations into a single, repeatable, and secure daily runbook. It’s adaptable, audit-friendly, and ideal for enterprise environments requiring consistency across clusters.
External Documentation:
Table of Contents 1. Introduction: Why Air-Gapped DR for Nutanix? Modern cyber threats—including ransomware and nation-state actors—have exposed the vulnerability of traditional...
