123456789101112131415161718192021222324252627 |
- #!/bin/bash
- # Load environment variables from .env file
- source .env
- # Execute unmount command on the server via SSH and capture output
- OUTPUT=$(ssh -i "$SSH_KEY" -p "$SSH_PORT" "$SERVER_USER@$SERVER_IP" << EOF
- # Try to unmount the HDD and handle errors
- sudo /usr/bin/sync "$MOUNT_POINT"
- sudo /bin/umount "$MOUNT_POINT" $1
- if [ \$? -ne 0 ]; then
- echo "Failed to unmount HDD from $MOUNT_POINT."
- exit 1
- else
- echo "HDD unmounted from $MOUNT_POINT."
- fi
- EOF
- )
- # Check if the SSH command was successful
- if [ $? -ne 0 ]; then
- echo "SSH command failed."
- exit 1
- fi
- # Print only the last line of the output
- echo "$OUTPUT" | tail -n 1
|