Wake up script #978
Unanswered
Ozan8
asked this question in
Help wanted
Replies: 1 comment 1 reply
-
I've put together a bash script which might help you. Adjust the variables at the top and also the rsync command. #!/bin/bash
# Configurations
UPSNAP_URL="http://localhost"
UPSNAP_USER="YOUR_EMAIL"
UPSNAP_PASSWORD="YOUR_PASSWORD"
UPSNAP_DEVICE_ID="YOUR_DEVICE_ID"
TIMEOUT=120
# Get authentication token
AUTH_TOKEN=$(curl -s -X POST "$UPSNAP_URL/api/collections/_superusers/auth-with-password" \
-H "Content-Type: application/json" \
-d "{\"identity\": \"$UPSNAP_USER\", \"password\": \"$UPSNAP_PASSWORD\"}" | jq -r '.token')
if [[ -z "$AUTH_TOKEN" ]]; then
echo "Auth token is empty. Failed to authenticate. Exiting."
exit 1
fi
echo "Authentication successful. Token acquired."
# Wake up the device
curl -s "$UPSNAP_URL/api/upsnap/wake/$UPSNAP_DEVICE_ID" \
-H "Authorization: Bearer $AUTH_TOKEN"
echo "Wake request sent. Waiting $TIMEOUT seconds for the device to come online..."
# Wait until the device is online
START_TIME=$(date +%s)
while true; do
STATUS=$(curl -s "$UPSNAP_URL/api/collections/devices/records/$UPSNAP_DEVICE_ID" \
-H "Authorization: Bearer $AUTH_TOKEN" | jq -r '.status')
if [[ "$STATUS" == "online" ]]; then
echo "Device is online!"
break
fi
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [[ $ELAPSED_TIME -ge $TIMEOUT ]]; then
echo "Timeout reached. Device did not come online. Exiting."
exit 1
fi
sleep 1
done
# Perform rsync
rsync -avz --progress src/ target/
# Shutdown the device
curl -s "$UPSNAP_URL/api/upsnap/shutdown/$UPSNAP_DEVICE_ID" \
-H "Authorization: Bearer $AUTH_TOKEN"
echo "Shutdown request sent." |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! this works like a charm. I wanted to understand if there is a way for me to use this tool through CLI. I want to turn on my nas, then use rsync to backup some data and turn it off. I have this bash script in my mind. But I cannot wake my NAS with wakeonlan, or etherwake, but only can do so with UpSnap (kudos to you again). is there anyone who can help me with this?
Beta Was this translation helpful? Give feedback.
All reactions