Dynamic logic in environment variable? The Next CEO of Stack Overflowlinux: how to permanently...
Why does the UK parliament need a vote on the political declaration?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
What benefits would be gained by using human laborers instead of drones in deep sea mining?
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Between two walls
If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?
Is "for causing autism in X" grammatical?
Bold, vivid family
What is the result of assigning to std::vector<T>::begin()?
Would a galaxy be visible from outside, but nearby?
Received an invoice from my ex-employer billing me for training; how to handle?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
What was the first Unix version to run on a microcomputer?
What connection does MS Office have to Netscape Navigator?
sp_blitzCache results Memory grants
Should I tutor a student who I know has cheated on their homework?
Complex fractions
Is there a way to save my career from absolute disaster?
Is HostGator storing my password in plaintext?
Can you replace a racial trait cantrip when leveling up?
What expression will give age in years in QGIS?
In excess I'm lethal
How to solve a differential equation with a term to a power?
Dynamic logic in environment variable?
The Next CEO of Stack Overflowlinux: how to permanently and globally change environment variablesHow to determine if a bash variable is empty?How do you add a Windows environment variable without rebooting?Environment variables of a running process on Unix?SSH - set env vairables by every connection - godaddy shared hostWhich environment variable contains…Preventing bash tab completion of an environment variable with a FS path value from removing the environment variable nameEnvironment variable not available in pythonEnvironment variablephp-fpm and Nginx dynamic environment variablessh configuration file environment variable?
I regularly invoke a particular remote server from a (Linux/bash) command line via tools like cURL or wget. This server requires an authentication token that expires every 10 minutes. I have a program that can generate a new token.
What I would like is an environment variable, $TOKEN, that I can use from the command line, that refreshes itself every 10 minutes, or, better yet, refreshes itself only when requested, and even then only every 10 minutes at most.
I was hoping that there was a way to tie an environment variable's evaluation to an executable, allowing me to do so with a script. Failing that, I was wondering if perhaps there was a way to set up a background process that updated the environment variable every 10 minutes.
linux bash environment-variables
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I regularly invoke a particular remote server from a (Linux/bash) command line via tools like cURL or wget. This server requires an authentication token that expires every 10 minutes. I have a program that can generate a new token.
What I would like is an environment variable, $TOKEN, that I can use from the command line, that refreshes itself every 10 minutes, or, better yet, refreshes itself only when requested, and even then only every 10 minutes at most.
I was hoping that there was a way to tie an environment variable's evaluation to an executable, allowing me to do so with a script. Failing that, I was wondering if perhaps there was a way to set up a background process that updated the environment variable every 10 minutes.
linux bash environment-variables
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I regularly invoke a particular remote server from a (Linux/bash) command line via tools like cURL or wget. This server requires an authentication token that expires every 10 minutes. I have a program that can generate a new token.
What I would like is an environment variable, $TOKEN, that I can use from the command line, that refreshes itself every 10 minutes, or, better yet, refreshes itself only when requested, and even then only every 10 minutes at most.
I was hoping that there was a way to tie an environment variable's evaluation to an executable, allowing me to do so with a script. Failing that, I was wondering if perhaps there was a way to set up a background process that updated the environment variable every 10 minutes.
linux bash environment-variables
I regularly invoke a particular remote server from a (Linux/bash) command line via tools like cURL or wget. This server requires an authentication token that expires every 10 minutes. I have a program that can generate a new token.
What I would like is an environment variable, $TOKEN, that I can use from the command line, that refreshes itself every 10 minutes, or, better yet, refreshes itself only when requested, and even then only every 10 minutes at most.
I was hoping that there was a way to tie an environment variable's evaluation to an executable, allowing me to do so with a script. Failing that, I was wondering if perhaps there was a way to set up a background process that updated the environment variable every 10 minutes.
linux bash environment-variables
linux bash environment-variables
asked Sep 25 '13 at 17:07
Brandon YarbroughBrandon Yarbrough
35518
35518
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You could set up a cron job that calls a script every 10 minutes (or whatever time interval you want). Then the script updates the variable.
See: linux: how to permanently and globally change environment variables
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
add a comment |
you could create an alias to update the env var
alias token='TOKEN=$(wget -q -O - http://webserver.com/TOKEN)'
or
alias token='TOKEN=$(/path/to/token-generator)'
then, simply running "token" will set that var for current session
you can add to your bash profile, so the alias remains accross logins
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
2
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
add a comment |
Store two environment variables, TOKEN
and TOKEN_TIMESTAMP
.
if [ $(($(date +%s) - $TOKEN_TIMESTAMP)) -ge 600 ]; then
/script/to/update/token.sh
TOKEN_TIMESTAMP=$(date +%s) # this should be in the above script.
fi
/script/that/uses/token.sh # everything could be in this one script.
This way you don't have to store logic in an environment variable [ew] or set up a cron job. The token is refreshed on-demand.
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
In Bash:if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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%2fserverfault.com%2fquestions%2f541623%2fdynamic-logic-in-environment-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could set up a cron job that calls a script every 10 minutes (or whatever time interval you want). Then the script updates the variable.
See: linux: how to permanently and globally change environment variables
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
add a comment |
You could set up a cron job that calls a script every 10 minutes (or whatever time interval you want). Then the script updates the variable.
See: linux: how to permanently and globally change environment variables
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
add a comment |
You could set up a cron job that calls a script every 10 minutes (or whatever time interval you want). Then the script updates the variable.
See: linux: how to permanently and globally change environment variables
You could set up a cron job that calls a script every 10 minutes (or whatever time interval you want). Then the script updates the variable.
See: linux: how to permanently and globally change environment variables
edited Apr 13 '17 at 12:14
Community♦
1
1
answered Sep 25 '13 at 17:17
smcgsmcg
410316
410316
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
add a comment |
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
I would recommend this, but use a file to store the value since variables set in the cron job would only be available to its children and not to arbitrary processes. The question and answers you linked to aren't applicable to this question.
– Dennis Williamson
Sep 26 '13 at 1:43
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
it has useful information about cron jobs and environment variables.
– smcg
Sep 26 '13 at 13:49
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
That's true, but it's applicable here.
– Dennis Williamson
Sep 26 '13 at 13:52
add a comment |
you could create an alias to update the env var
alias token='TOKEN=$(wget -q -O - http://webserver.com/TOKEN)'
or
alias token='TOKEN=$(/path/to/token-generator)'
then, simply running "token" will set that var for current session
you can add to your bash profile, so the alias remains accross logins
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
2
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
add a comment |
you could create an alias to update the env var
alias token='TOKEN=$(wget -q -O - http://webserver.com/TOKEN)'
or
alias token='TOKEN=$(/path/to/token-generator)'
then, simply running "token" will set that var for current session
you can add to your bash profile, so the alias remains accross logins
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
2
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
add a comment |
you could create an alias to update the env var
alias token='TOKEN=$(wget -q -O - http://webserver.com/TOKEN)'
or
alias token='TOKEN=$(/path/to/token-generator)'
then, simply running "token" will set that var for current session
you can add to your bash profile, so the alias remains accross logins
you could create an alias to update the env var
alias token='TOKEN=$(wget -q -O - http://webserver.com/TOKEN)'
or
alias token='TOKEN=$(/path/to/token-generator)'
then, simply running "token" will set that var for current session
you can add to your bash profile, so the alias remains accross logins
answered Sep 25 '13 at 17:36
nandoPnandoP
1,854614
1,854614
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
2
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
add a comment |
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
2
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
Well, yeah, but then I need to remember to run "token" every so often. That's what I'm trying to avoid.
– Brandon Yarbrough
Sep 25 '13 at 17:48
2
2
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
if you write a script that returns the token and checks for invalid/old ones, then prints it to stdout, you can invoke it as $(scriptname). If you wish to optimize out the script call, you may be able to build a bash function that has the same effect but checks the age of the cookie first (in a different variable). That variable wouldn't be shared across different scripts though, unless it was reading from a shared file of some sort.
– Andrew Domaszek
Sep 25 '13 at 18:15
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
Ahhhhh, I had forgotten about the $(executable) trick. That's perfect, thanks!
– Brandon Yarbrough
Sep 25 '13 at 19:14
add a comment |
Store two environment variables, TOKEN
and TOKEN_TIMESTAMP
.
if [ $(($(date +%s) - $TOKEN_TIMESTAMP)) -ge 600 ]; then
/script/to/update/token.sh
TOKEN_TIMESTAMP=$(date +%s) # this should be in the above script.
fi
/script/that/uses/token.sh # everything could be in this one script.
This way you don't have to store logic in an environment variable [ew] or set up a cron job. The token is refreshed on-demand.
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
In Bash:if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
add a comment |
Store two environment variables, TOKEN
and TOKEN_TIMESTAMP
.
if [ $(($(date +%s) - $TOKEN_TIMESTAMP)) -ge 600 ]; then
/script/to/update/token.sh
TOKEN_TIMESTAMP=$(date +%s) # this should be in the above script.
fi
/script/that/uses/token.sh # everything could be in this one script.
This way you don't have to store logic in an environment variable [ew] or set up a cron job. The token is refreshed on-demand.
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
In Bash:if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
add a comment |
Store two environment variables, TOKEN
and TOKEN_TIMESTAMP
.
if [ $(($(date +%s) - $TOKEN_TIMESTAMP)) -ge 600 ]; then
/script/to/update/token.sh
TOKEN_TIMESTAMP=$(date +%s) # this should be in the above script.
fi
/script/that/uses/token.sh # everything could be in this one script.
This way you don't have to store logic in an environment variable [ew] or set up a cron job. The token is refreshed on-demand.
Store two environment variables, TOKEN
and TOKEN_TIMESTAMP
.
if [ $(($(date +%s) - $TOKEN_TIMESTAMP)) -ge 600 ]; then
/script/to/update/token.sh
TOKEN_TIMESTAMP=$(date +%s) # this should be in the above script.
fi
/script/that/uses/token.sh # everything could be in this one script.
This way you don't have to store logic in an environment variable [ew] or set up a cron job. The token is refreshed on-demand.
answered Sep 25 '13 at 18:21
SammitchSammitch
1,5941231
1,5941231
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
In Bash:if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
add a comment |
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
In Bash:if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
Hrm...I was hoping that the token would just be available for use with arbitrary, ad-hoc commands. Perhaps I could trigger a script like this on every new prompt, but ew.
– Brandon Yarbrough
Sep 25 '13 at 18:48
In Bash:
if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
In Bash:
if (( $(date +%s) - TOKEN_TIMESTAMP >= 600 ))
– Dennis Williamson
Sep 26 '13 at 1:37
add a comment |
Thanks for contributing an answer to Server Fault!
- 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%2fserverfault.com%2fquestions%2f541623%2fdynamic-logic-in-environment-variable%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