123456789101112131415161718192021222324252627282930 |
- #!/bin/bash
- # Load environment variables from .env file
- source .env
- # Execute mount command on the server via SSH and capture output
- OUTPUT=$(ssh -i "$SSH_KEY" -p "$SSH_PORT" "$SERVER_USER@$SERVER_IP" << EOF
- if mountpoint -q "$MOUNT_POINT"; then
- echo "HDD is already mounted."
- else
- # Try to mount the HDD and handle errors
- sudo /bin/mount "$HDD_DEVICE" "$MOUNT_POINT"
- if [ \$? -ne 0 ]; then
- echo "Failed to mount HDD at $MOUNT_POINT."
- exit 1
- else
- echo "HDD mounted at $MOUNT_POINT."
- fi
- 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
|