mount_hdd.sh 772 B

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