Content
Erda Mount Script
While we're working on an easier system for ERDA mounting on Slurm-HPC, we've tested and provided this script for use until then. Remember to add your own ERDA password and username into the script.
#!/bin/bash
#SBATCH --job-name=yourjobname
#SBATCH --partition=min
# ===== CONFIG =====
REMOTE_NAME="ERDA"
SFTP_HOST="io.erda.au.dk"
SFTP_USERNAME="YOUR_ERDA_EMAIL_HERE"
SFTP_PORT="2222"
# for password - go into erda -> bottom left user icon -> setup -> SFTP -> put something in the password
SFTP_PASSWORD="$(rclone obscure 'YOUR_ERDA_PASSWORD_HERE')"
# ===== CONFIG END =====
# ==== System Config - Dont touch unless you know what youre doing ====
RCLONE_REMOTE="sftp-remote:/"
MOUNT_POINT="/mnt/sftp"
RCLONE_CONFIG="$HOME/.config/rclone/rclone.conf"
RCLONE_LOG="$TMP_DIR/rclone.log"
RCLONE_CONFIG="$TMP_DIR/rclone.conf"
TMP_DIR="$(mktemp -d)"
cleanup() {
fusermount -u "$MOUNT_POINT" 2>/dev/null || true
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
# Install rclone and fusermount if not present
echo "Installing rclone..."
if ! command -v rclone >/dev/null 2>&1; then
curl -fsSL https://rclone.org/install.sh | sudo bash
fi
if ! command -v fusermount >/dev/null 2>&1 && ! command -v fusermount3 >/dev/null 2>&1; then
echo "Installing fuse utilities..."
sudo dnf install -y fuse fuse3 fuse-sshfs || true
fi
# There is some errors sometimes where rclone will try to use the old name for FUSE. We just symlink them here and it should be fine
if ! command -v fusermount >/dev/null 2>&1 && command -v fusermount3 >/dev/null 2>&1; then
echo "Creating symlink for fusermount -> fusermount3"
sudo ln -sf "$(which fusermount3)" /usr/local/bin/fusermount
fi
sudo mkdir -p "$MOUNT_POINT"
sudo chown "$USER":"$USER" "$MOUNT_POINT"
cat > "$RCLONE_CONFIG" <<EOF
[sftp-remote]
type = sftp
host = ${SFTP_HOST}
port = ${SFTP_PORT}
user = ${SFTP_USERNAME}
pass = ${SFTP_PASSWORD}
EOF
# Test remote reachability (optional quick TCP check)
echo "Testing SFTP host reachability..."
if ! timeout 10 bash -c "</dev/tcp/${SFTP_HOST}/${SFTP_PORT}" 2>/dev/null; then
echo "WARNING: SFTP host not reachable. Proceeding; mount may fail."
fi
echo "Testing rclone remote access with 'lsf'..."
if ! rclone --config "$RCLONE_CONFIG" lsf "$RCLONE_REMOTE" --max-depth 1 --timeout=30s | head -n 5; then
echo "ERROR: rclone remote '$RCLONE_REMOTE' is not accessible (credentials/network)."
exit 1
fi
# Ensure FUSE allows access for non-owner (Docker daemon runs as root)
if sudo test -f /etc/fuse.conf && ! sudo grep -q '^user_allow_other' /etc/fuse.conf; then
echo "Enabling user_allow_other in /etc/fuse.conf..."
echo 'user_allow_other' | sudo tee -a /etc/fuse.conf >/dev/null
fi
# Mount remote using rclone (daemonized) with external log
echo "Mounting remote $RCLONE_REMOTE at $MOUNT_POINT using rclone..."
set +e
rclone --config "$RCLONE_CONFIG" mount "$RCLONE_REMOTE" "$MOUNT_POINT" \
--daemon \
--vfs-cache-mode full \
--timeout=60s \
--contimeout=20s \
--log-level DEBUG \
--log-file "$RCLONE_LOG" \
--allow-other
RC=$?
set -e
if [ $RC -ne 0 ]; then
echo "ERROR: rclone mount failed with exit code $RC"
echo "----- rclone log (last 200 lines) -----"
tail -n 200 "$RCLONE_LOG" || true
exit $RC
fi
# Wait for mount readiness
echo "Waiting for rclone mount to become ready..."
READY=0
for i in {1..30}; do
if timeout 5 ls "$MOUNT_POINT" >/dev/null 2>&1; then
READY=1
echo "rclone mount is ready at $MOUNT_POINT"
break
fi
sleep 1
done
if [ $READY -ne 1 ]; then
echo "ERROR: rclone mount did not become ready in time"
echo "----- rclone log (last 200 lines) -----"
tail -n 200 "$RCLONE_LOG" || true
exit 1
fi
# YOUR SCRIPT GOES HERE
echo sleeping 30
sleep 30