How can I set a variable each day that is used by my daily scripts
How can I update a variable each day, that each of my daily crontab scripts would have access to?
I'm trying to set a random number, that changes each day, and read it from my scripts. Here is what my crontab looks like:
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
In order to avoid this turning into an XY problem, here is what I'm trying to achieve: I need to run the first script at a random time after 10AM (specifically 1-10 minutes after the hour). The second script needs to be run exactly one hour after the first. And the third needs to be run exactly one hour after the second. So my idea was to set an environment variable in a script that runs before the others. The environment variable would be the amount of time to sleep
in minutes. Like this:
0 9 * * 1-5 source /home/myuserdir/setup.sh
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
And setup.sh
looks like this:
#!/bin/bash
export OFFSET=$((1 + RANDOM % 10))
But it looks like the environment variable is not preserved. How can I create an environment variable that is accessible to each of my three scripts. It is also important that it changes each day. Is there another way to achive my goal? Are there any alternatives?
cron
add a comment |
How can I update a variable each day, that each of my daily crontab scripts would have access to?
I'm trying to set a random number, that changes each day, and read it from my scripts. Here is what my crontab looks like:
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
In order to avoid this turning into an XY problem, here is what I'm trying to achieve: I need to run the first script at a random time after 10AM (specifically 1-10 minutes after the hour). The second script needs to be run exactly one hour after the first. And the third needs to be run exactly one hour after the second. So my idea was to set an environment variable in a script that runs before the others. The environment variable would be the amount of time to sleep
in minutes. Like this:
0 9 * * 1-5 source /home/myuserdir/setup.sh
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
And setup.sh
looks like this:
#!/bin/bash
export OFFSET=$((1 + RANDOM % 10))
But it looks like the environment variable is not preserved. How can I create an environment variable that is accessible to each of my three scripts. It is also important that it changes each day. Is there another way to achive my goal? Are there any alternatives?
cron
Wouldn't it be simpler to have a single master script that executesscript1.sh
after the random time, and thensleep
s for one hour before executingscript2.sh
(and so on)?
– steeldriver
Jan 11 at 4:00
@steeldriver Yes possibly, but actually I want to wait for about 5 or 6 hours. I just said 1 hour to make it simple.
– Kodos Johnson
Jan 11 at 4:01
add a comment |
How can I update a variable each day, that each of my daily crontab scripts would have access to?
I'm trying to set a random number, that changes each day, and read it from my scripts. Here is what my crontab looks like:
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
In order to avoid this turning into an XY problem, here is what I'm trying to achieve: I need to run the first script at a random time after 10AM (specifically 1-10 minutes after the hour). The second script needs to be run exactly one hour after the first. And the third needs to be run exactly one hour after the second. So my idea was to set an environment variable in a script that runs before the others. The environment variable would be the amount of time to sleep
in minutes. Like this:
0 9 * * 1-5 source /home/myuserdir/setup.sh
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
And setup.sh
looks like this:
#!/bin/bash
export OFFSET=$((1 + RANDOM % 10))
But it looks like the environment variable is not preserved. How can I create an environment variable that is accessible to each of my three scripts. It is also important that it changes each day. Is there another way to achive my goal? Are there any alternatives?
cron
How can I update a variable each day, that each of my daily crontab scripts would have access to?
I'm trying to set a random number, that changes each day, and read it from my scripts. Here is what my crontab looks like:
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
In order to avoid this turning into an XY problem, here is what I'm trying to achieve: I need to run the first script at a random time after 10AM (specifically 1-10 minutes after the hour). The second script needs to be run exactly one hour after the first. And the third needs to be run exactly one hour after the second. So my idea was to set an environment variable in a script that runs before the others. The environment variable would be the amount of time to sleep
in minutes. Like this:
0 9 * * 1-5 source /home/myuserdir/setup.sh
0 10 * * 1-5 /home/myuserdir/script1.sh
0 11 * * 1-5 /home/myuserdir/script2.sh
0 12 * * 1-5 /home/myuserdir/script3.sh
And setup.sh
looks like this:
#!/bin/bash
export OFFSET=$((1 + RANDOM % 10))
But it looks like the environment variable is not preserved. How can I create an environment variable that is accessible to each of my three scripts. It is also important that it changes each day. Is there another way to achive my goal? Are there any alternatives?
cron
cron
edited Jan 11 at 4:00
Kodos Johnson
asked Jan 11 at 3:54
Kodos JohnsonKodos Johnson
1127
1127
Wouldn't it be simpler to have a single master script that executesscript1.sh
after the random time, and thensleep
s for one hour before executingscript2.sh
(and so on)?
– steeldriver
Jan 11 at 4:00
@steeldriver Yes possibly, but actually I want to wait for about 5 or 6 hours. I just said 1 hour to make it simple.
– Kodos Johnson
Jan 11 at 4:01
add a comment |
Wouldn't it be simpler to have a single master script that executesscript1.sh
after the random time, and thensleep
s for one hour before executingscript2.sh
(and so on)?
– steeldriver
Jan 11 at 4:00
@steeldriver Yes possibly, but actually I want to wait for about 5 or 6 hours. I just said 1 hour to make it simple.
– Kodos Johnson
Jan 11 at 4:01
Wouldn't it be simpler to have a single master script that executes
script1.sh
after the random time, and then sleep
s for one hour before executing script2.sh
(and so on)?– steeldriver
Jan 11 at 4:00
Wouldn't it be simpler to have a single master script that executes
script1.sh
after the random time, and then sleep
s for one hour before executing script2.sh
(and so on)?– steeldriver
Jan 11 at 4:00
@steeldriver Yes possibly, but actually I want to wait for about 5 or 6 hours. I just said 1 hour to make it simple.
– Kodos Johnson
Jan 11 at 4:01
@steeldriver Yes possibly, but actually I want to wait for about 5 or 6 hours. I just said 1 hour to make it simple.
– Kodos Johnson
Jan 11 at 4:01
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f1108751%2fhow-can-i-set-a-variable-each-day-that-is-used-by-my-daily-scripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1108751%2fhow-can-i-set-a-variable-each-day-that-is-used-by-my-daily-scripts%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
Wouldn't it be simpler to have a single master script that executes
script1.sh
after the random time, and thensleep
s for one hour before executingscript2.sh
(and so on)?– steeldriver
Jan 11 at 4:00
@steeldriver Yes possibly, but actually I want to wait for about 5 or 6 hours. I just said 1 hour to make it simple.
– Kodos Johnson
Jan 11 at 4:01