LINUX.ORG.RU

История изменений

Исправление theNamelessOne, (текущая версия) :

#!/bin/bash

BASE_URL="http://pic4a.ru"
UPLOAD_URL="${BASE_URL}/upload/"
CSRF_TOKEN_PARAM="csrfmiddlewaretoken"
CSRF_COOKIE="csrftoken"

token=$(curl $BASE_URL 2>/dev/null | awk -F\' "/${CSRF_TOKEN_PARAM}/{print \$(NF - 1)}")
name=$(curl $UPLOAD_URL -# -H 'Accept-Encoding: gzip' \
            -b "${CSRF_COOKIE}=${token}" -F "${CSRF_TOKEN_PARAM}=${token}" -F "files[]=@$1" \
          | sed 's/^.*"name":\s*"\([^"]*\)".*$/\1/')
echo "${BASE_URL}/${name}"

Исходная версия theNamelessOne, :

Как-то так

#!/bin/bash

BASE_URL="http://pic4a.ru"
UPLOAD_URL="${BASE_URL}/upload/"
CSRF_TOKEN_PARAM="csrfmiddlewaretoken"
CSRF_COOKIE="csrftoken"

token=$(curl $BASE_URL 2>/dev/null | awk -F\' "/${CSRF_TOKEN_PARAM}/{print \$(NF - 1)}")
name=$(curl $UPLOAD_URL -# -H 'Accept-Encoding: gzip' \
            -b "${CSRF_COOKIE}=${token}" -F "${CSRF_TOKEN_PARAM}=${token}" -F "files[]=@$1" \
          | sed "s/^.*\"name\":\s*\"\([^\"]*\)\".*$/\1/")
echo "${BASE_URL}/${name}"