Need to associate one field with another in event, using bash script
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
shell-script json jq
New contributor
add a comment |
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
shell-script json jq
New contributor
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
add a comment |
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
shell-script json jq
New contributor
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
shell-script json jq
shell-script json jq
New contributor
New contributor
edited Jan 15 at 13:15
manderson
New contributor
asked Jan 14 at 20:56
mandersonmanderson
11
11
New contributor
New contributor
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
add a comment |
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
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
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
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
Please put that in your question, where it can be seen easily by anyone considering answering.
– roaima
Jan 14 at 21:57
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
manderson is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494496%2fneed-to-associate-one-field-with-another-in-event-using-bash-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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 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
answered Jan 14 at 23:04
community wiki
glenn jackman
add a comment |
add a comment |
manderson is a new contributor. Be nice, and check out our Code of Conduct.
manderson is a new contributor. Be nice, and check out our Code of Conduct.
manderson is a new contributor. Be nice, and check out our Code of Conduct.
manderson is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494496%2fneed-to-associate-one-field-with-another-in-event-using-bash-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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