Last active
September 22, 2023 16:43
-
-
Save fortran01/bd17dbfecc2d79f5191095564d46cc77 to your computer and use it in GitHub Desktop.
Install machine-stats scheduled task in *nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Execute the command `tidal doctor` and check for the required strings | |
output=$(tidal doctor) | |
required_strings=("Tidal Accelerator API connect OK" "Pull from registry OK" "Version is up to date" "Tidal Accelerator API connection configured OK") | |
for string in "${required_strings[@]}"; do | |
if [[ ! $output =~ $string ]]; then | |
echo "Error: '$string' not found in the output of 'tidal doctor'" | |
exit 1 | |
fi | |
done | |
# Check if /home/ubuntu/hosts exists | |
if [[ ! -f /home/ubuntu/hosts ]]; then | |
echo "Error: /home/ubuntu/hosts does not exist. Please populate the inventory in /home/ubuntu/hosts" | |
exit 1 | |
fi | |
# Create the script /home/ubuntu/run-machine-stats.sh | |
cat > /home/ubuntu/run-machine-stats.sh << 'EOF' | |
#!/bin/bash | |
/usr/local/bin/machine-stats /home/ubuntu/hosts --cpu-utilization-only-value --cpu-utilization-timeout 1 -m | /home/ubuntu/bin/tidal request -X POST /api/v1/measurements/import | |
EOF | |
# Make the script executable | |
chmod +x /home/ubuntu/run-machine-stats.sh | |
# Schedule the script to run in crontab every 5 minutes | |
(crontab -l 2>/dev/null; echo "*/5 * * * * /home/ubuntu/run-machine-stats.sh") | crontab - | |
# Show the contents of crontab to verify the schedule | |
crontab -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment