fetch backup status in bash script fails

ruudux

Verified User
Joined
Apr 18, 2024
Messages
7
For my managed DirectAdmin servers I would like to verify if backups are finished correctly using a bash script. The system.log tells me only that a tally run started and completed, but not if there is an error. So I created a login key pair and assigned the correct permissions. I created the following script and made it executable on the localhost for testing.
```
#!/bin/bash
# DirectAdmin credentials
API_KEY='mykey'
DOMAIN='server.example.com'
# Function to check backup status
check_backup_status() {
API_URL="https://$DOMAIN:2222/CMD_API_BACKUP"
RESPONSE=$(curl -s -H "Authorization: $API_KEY" "$API_URL?action=list")
# Check if the backup is finished
if echo "$RESPONSE" | grep -q '"status":"finished"'; then
echo "Backup is finished."
elif echo "$RESPONSE" | grep -q '"status":"in_progress"'; then
echo "Backup is still in progress."
elif echo "$RESPONSE" | grep -q '"status":"error"'; then
echo "Backup finished with errors."
else
echo "Backup status could not be determined."
fi
}
# Call the function
check_backup_status
```
Sadly the echo "$RESPONSE" result I get if I run the script:
```
<a href="/">Found</a>.
```
What do I do wrong? Thanks in advance for the support.
 
Back
Top