????JFIF??x?x????'
Server IP : 79.136.114.73 / Your IP : 216.73.216.21 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/b8009/ |
Upload File : |
#!/usr/bin/env bash set -euo pipefail # ================================ # Kopiera endast toppmappar med namn 1–4 siffror # från www4:/var/www/icad_files till # oneit:/var/www/icad_files via SFTP (utan loggning) # ================================ # ---- Konfig ---- SRC_BASE="/var/www/icad_files" DEST_HOST="oneit.astacus.se" DEST_USER="b8009" DEST_BASE="/var/www/icad_files" SSH_KEY="${HOME}/.ssh/id_ed25519" # Toggle: torrkörning (true/false). Kan även sättas via miljövariabel. DRY_RUN="${DRY_RUN:-false}" # Antal försök per mapp RETRIES="${RETRIES:-1}" # ---- Förkontroller ---- command -v sftp >/dev/null 2>&1 || { echo "sftp saknas"; exit 1; } command -v find >/dev/null 2>&1 || { echo "find saknas"; exit 1; } [[ -d "${SRC_BASE}" ]] || { echo "Källmapp saknas: ${SRC_BASE}"; exit 1; } [[ -r "${SSH_KEY}" ]] || { echo "SSH-nyckel saknas/oläslig: ${SSH_KEY}"; exit 1; } # ---- SFTP-alternativ (inga known_hosts-krav, fungerar på äldre klienter) ---- sftp_opts=( -i "${SSH_KEY}" -o BatchMode=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=15 -o ServerAliveCountMax=3 ) echo "Start: ${SRC_BASE} -> ${DEST_USER}@${DEST_HOST}:${DEST_BASE}" [[ "${DRY_RUN}" == "true" ]] && echo "DRY_RUN = true (ingen kopiering)" # Testa anslutning if ! printf "pwd\n" | sftp "${sftp_opts[@]}" "${DEST_USER}@${DEST_HOST}" >/dev/null 2>&1; then echo "SFTP-anslutning misslyckades (nyckel/nät?). Avbryter." exit 1 fi # Skapa målbas (ignorera fel om den finns) if [[ "${DRY_RUN}" == "false" ]]; then printf 'mkdir %s\n' "${DEST_BASE}" | sftp "${sftp_opts[@]}" "${DEST_USER}@${DEST_HOST}" >/dev/null 2>&1 || true fi # Hitta toppnivåmappar som är exakt 1–4 siffror mapfile -t DIRS < <(find "${SRC_BASE}" -mindepth 1 -maxdepth 1 -type d \ -regextype posix-extended -regex ".*/[0-9]{1,4}$" | sort) if [[ "${#DIRS[@]}" -eq 0 ]]; then echo "Inga matchande mappar (1–4 siffror) hittades. Klart." exit 0 fi echo "Antal mappar att kopiera: ${#DIRS[@]}" # Kopieringsloop for src_dir in "${DIRS[@]}"; do name="$(basename "${src_dir}")" echo "Kopierar: ${name}" read -r -d '' batch <<BATCH || true lcd ${SRC_BASE} cd ${DEST_BASE} mkdir ${name} put -pr ${name} BATCH if [[ "${DRY_RUN}" == "true" ]]; then echo " (torrkörning) skulle köra SFTP-batch för ${name}" continue fi attempt=0 ok=false while (( attempt <= RETRIES )); do if printf '%s\n' "${batch}" | sftp "${sftp_opts[@]}" "${DEST_USER}@${DEST_HOST}" >/dev/null 2>&1; then ok=true break else echo " Försök $((attempt+1)) misslyckades för ${name}, provar igen..." sleep 2 fi ((attempt++)) done if [[ "${ok}" != "true" ]]; then echo " PERMANENT FEL för ${name}, går vidare." fi done echo "Klart."