From 1024d688030e6ea7e021fe74414beb4b7eabaa2f Mon Sep 17 00:00:00 2001 From: wy580477 <98247050+wy580477@users.noreply.github.com> Date: Sun, 19 Jun 2022 19:30:36 +0800 Subject: [PATCH] return Rclone job info to logs --- content/aria2/upload.sh | 8 ++++---- content/gdltorclone.sh | 8 ++++---- content/pyload_to_rclone.sh | 6 +++--- content/pyload_to_rclone_package_extracted.sh | 6 +++--- content/qbittorclone.sh | 12 ++++++------ content/ytdlptorclone.sh | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/content/aria2/upload.sh b/content/aria2/upload.sh index cc38482..fbf051a 100644 --- a/content/aria2/upload.sh +++ b/content/aria2/upload.sh @@ -94,14 +94,14 @@ UPLOAD_FILE() { echo ) if [ -f "${LOCAL_PATH}" ]; then - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${DOWNLOAD_DIR}"'","srcRemote":"'"${TASK_FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${TASK_FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${DOWNLOAD_DIR}"'","srcRemote":"'"${TASK_FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${TASK_FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" else - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${LOCAL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${LOCAL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" fi - RCLONE_EXIT_CODE=$? - if [ ${RCLONE_EXIT_CODE} -eq 0 ]; then + if [ "${JOB_ID}" != "" ]; then UPLOAD_LOG="$(DATE_TIME) ${INFO} Successfully send job to rclone: ${LOCAL_PATH} -> ${REMOTE_PATH}" OUTPUT_UPLOAD_LOG + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' DELETE_EMPTY_DIR break else diff --git a/content/gdltorclone.sh b/content/gdltorclone.sh index b4b1454..4bea4f8 100644 --- a/content/gdltorclone.sh +++ b/content/gdltorclone.sh @@ -32,10 +32,10 @@ REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${BASE_PATH}" if [ "${UPLOAD_MODE}" = "disable" ]; then echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${DL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' - EXIT_CODE=$? - if [ ${EXIT_CODE} -eq 0 ]; then + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${DL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' else echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $1" fi @@ -43,4 +43,4 @@ fi if [[ "${DELETE_EMPTY_DIR}" = "true" ]]; then find ${DOWNLOAD_DIR} -depth -mindepth 1 -type d -empty -exec rm -vrf {} \; 2>/dev/null -fi \ No newline at end of file +fi diff --git a/content/pyload_to_rclone.sh b/content/pyload_to_rclone.sh index 3b875e9..d4ae982 100644 --- a/content/pyload_to_rclone.sh +++ b/content/pyload_to_rclone.sh @@ -32,10 +32,10 @@ REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${DEST_PATH_SUFFIX}" if [ "${UPLOAD_MODE}" = "disable" ]; then echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"$2"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"$2"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' - EXIT_CODE=$? - if [ ${EXIT_CODE} -eq 0 ]; then + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"$2"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"$2"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $3 -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' else echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $3" fi diff --git a/content/pyload_to_rclone_package_extracted.sh b/content/pyload_to_rclone_package_extracted.sh index 126ead0..3b8c644 100644 --- a/content/pyload_to_rclone_package_extracted.sh +++ b/content/pyload_to_rclone_package_extracted.sh @@ -30,10 +30,10 @@ REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}" if [ "${UPLOAD_MODE}" = "disable" ]; then echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"$3"'","dstFs":"'"${REMOTE_PATH}"'/'"$2"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' - EXIT_CODE=$? - if [ ${EXIT_CODE} -eq 0 ]; then + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"$3"'","dstFs":"'"${REMOTE_PATH}"'/'"$2"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $3 -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' else echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $3" fi diff --git a/content/qbittorclone.sh b/content/qbittorclone.sh index d6396b6..4ea9932 100644 --- a/content/qbittorclone.sh +++ b/content/qbittorclone.sh @@ -29,18 +29,18 @@ REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${DEST_PATH_SUFFIX}" if [ "${UPLOAD_MODE}" = "disable" ]; then echo "[INFO] Auto-upload to Rclone remote disabled" elif [ -f "$1" ]; then - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"${FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' - EXIT_CODE=$? - if [ ${EXIT_CODE} -eq 0 ]; then + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"${FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then echo "[INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' else echo "[ERROR] Failed to send job to rclone: $1" fi else - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"$1"'","dstFs":"'"${REMOTE_PATH}"'/'"$2"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' - EXIT_CODE=$? - if [ ${EXIT_CODE} -eq 0 ]; then + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"$1"'","dstFs":"'"${REMOTE_PATH}"'/'"$2"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then echo "[INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' else echo "[ERROR] Failed to send job to rclone: $1" fi diff --git a/content/ytdlptorclone.sh b/content/ytdlptorclone.sh index ec19ec0..9b09da9 100644 --- a/content/ytdlptorclone.sh +++ b/content/ytdlptorclone.sh @@ -31,10 +31,10 @@ mv "$1" "${FILEPATH}""${FILENAME}" if [ "${UPLOAD_MODE}" = "disable" ]; then echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILEPATH}"'","srcRemote":"'"${FILENAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILENAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' - EXIT_CODE=$? - if [ ${EXIT_CODE} -eq 0 ]; then + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILEPATH}"'","srcRemote":"'"${FILENAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILENAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' else echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $1" fi