이벤트의 한 필드를 다른 필드와 연결하려면 bash 스크립트를 사용해야 합니다.

이벤트의 한 필드를 다른 필드와 연결하려면 bash 스크립트를 사용해야 합니다.

해야 할 일을 대부분 완료했지만 여전히 마지막 부분에서 멈춰 있습니다. 다음에서 활동을 다운로드해야 합니다.이번 달, 그러나 URL은 월이 아닌 활동 ID와 연결됩니다(이치에 맞습니다). 이번 달을 이번 달의 캠페인 ID와 연결할 수 있어야 합니다.

내 스크립트는 다음과 같습니다

#!/bin/sh
#Retrieve phishline token
var=$(curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"bof_ticket_user": "nope",
"bof_ticket_pw": "nopenopenope",
"api_key": "nope-nope-nope-nope-nope"}' 
"https://api.phishline.com/nope/rest/authenticate" | jq -r ."data"."access_token")

#define latest campaign
var2=$(curl -X GET -H "Authorization: Bearer $var" -H "Cache-Control: no-cache" "https://api.phishline.com/nope/rest/campaigns" | jq -r ."data"[-1]."cutoffDate")
#Clean up cutoffDate variable to %Y-%m format
var3=$(echo $var2 | cut -c1-7)
# Assign current date in %Y-%m format
datedit=$("date +%Y-%m")

if datedit == $var3
#download latest campaign
curl -X GET -H "Authorization: Bearer $var" -H "Cache-Control: no-cache" "https://api.phishline.com/nope/rest/campaignresults/$whichvar"

누구든지 더 나은 결과를 얻을 수 있는 제안을 해줄 수 있나요? 편집: 이를 통해 내가 달성해야 할 작업이 명확해졌기를 바랍니다. 스크립트는 이번 달의 활동 데이터를 다운로드해야 합니다. 이번 달의 활동 데이터는 이번 달의 활동을 식별하기 위해 활동 목록의 "cutoffDate"를 해당 활동의 id 필드와 연결하여 찾습니다. 두 필드 모두 나머지/캠페인 결과에 표시됩니다.

답변1

귀하의 질문에서 무엇이 무엇에 매핑되는지 명확하지 않지만 bash 버전이 4보다 큰 경우 연관 배열을 사용할 수 있습니다.

declare -A mapping=(
    [2019-01]="some-id"
    [2019-02]="some-other-id"
)

mon=$(process that retrieves the YYYY-MM)
campaign_id=${mapping[$mon]}
if [[ -z $campaign_id ]]; then
    echo "no mapping for month $mon"
else
    go fetch with "$campaign_id"
fi

관련 정보