unmount_hdd.sh 645 B

1234567891011121314151617181920212223242526
  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 /bin/umount "$MOUNT_POINT" $1
  8. if [ \$? -ne 0 ]; then
  9. echo "Failed to unmount HDD from $MOUNT_POINT."
  10. exit 1
  11. else
  12. echo "HDD unmounted from $MOUNT_POINT."
  13. fi
  14. EOF
  15. )
  16. # Check if the SSH command was successful
  17. if [ $? -ne 0 ]; then
  18. echo "SSH command failed."
  19. exit 1
  20. fi
  21. # Print only the last line of the output
  22. echo "$OUTPUT" | tail -n 1