0

I've gotten most of what I need done, but am stuck at the last part. I need to download the campaign from this month, but the url is associated w/ a campaign id and not the month (makes sense). I need to be able to associate this month with the campaign id(s) of this month.

My script is thus:

#!/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"

Can anyone make any suggestions to make this better? Edit: Hopefully this will clarify what I need to get done: The script needs to download the current months campaign data. The current months campaign data is found by associating the "cutoffDate" in the campaign list to identify the campaign for this month, with the id field in that campaign. Both fields are shown in the rest/campaigns results

  • 1
    Apart from the syntax errors that could be found by posting your code into shellcheck.net, what's the question? – roaima Jan 14 at 21:10
  • The script needs to download the current months campaign data. The current months campaign data is found by associating the "cutoffDate" in the campaign list to identify the campaign for this month, with the id field in that campaign. Both fields are shown in the rest/campaigns results. – manderson Jan 14 at 21:21
  • Please put that in your question, where it can be seen easily by anyone considering answering. – roaima Jan 14 at 21:57
1

Your question is unclear about what maps to what, but if your bash version is >= 4, you can use an associative array:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.