unmount_hdd.sh 683 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # Load environment variables from .env file
  3. source .env
  4. # Execute unmount command on the server via SSH and capture output
  5. OUTPUT=$(ssh -i "$SSH_KEY" -p "$SSH_PORT" "$SERVER_USER@$SERVER_IP" << EOF
  6. # Try to unmount the HDD and handle errors
  7. sudo /usr/bin/sync "$MOUNT_POINT"
  8. sudo /bin/umount "$MOUNT_POINT" $1
  9. if [ \$? -ne 0 ]; then
  10. echo "Failed to unmount HDD from $MOUNT_POINT."
  11. exit 1
  12. else
  13. echo "HDD unmounted from $MOUNT_POINT."
  14. fi
  15. EOF
  16. )
  17. # Check if the SSH command was successful
  18. if [ $? -ne 0 ]; then
  19. echo "SSH command failed."
  20. exit 1
  21. fi
  22. # Print only the last line of the output
  23. echo "$OUTPUT" | tail -n 1