my cron command doesn’t workWhy doesn't this script output to a text file when run from cron?Ubuntu 12.04...
What would be some possible ways of escaping higher gravity planets?
What can I do to encourage my players to use their consumables?
smartctl reports overall health test as passed but the tests failed?
Can I travel from country A to country B to country C without going back to country A?
Does copper wire need to say it's copper?
What is an efficient way to digitize a family photo collection?
Create an animation that plots the following two functions
Promise.all returning empty objects
How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?
What's the reason that we have a different number of days each month?
Does rolling friction increase speed of a wheel?
Why don't you get burned by the wood benches in a sauna?
Is practicing on a digital piano harmful to an experienced piano player?
Players preemptively rolling, even though their rolls are useless or are checking the wrong skills
Where does documentation like business and software requirement spec docs fit in an agile project?
Taking an academic pseudonym?
"I showed the monkey himself in the mirror". Why is this sentence grammatical?
Are all power cords made equal?
Maybe pigeonhole problem?
Given a total recursive function, can you always compute its fixed-point?
Crack the bank account's password!
How do I avoid the "chosen hero" feeling?
Is it possible to detect 100% of SQLi with a simple regex?
Was Opportunity's last message to Earth "My battery is low and it's getting dark"?
my cron command doesn’t work
Why doesn't this script output to a text file when run from cron?Ubuntu 12.04 cron not executingWhy won't cron run my sh script?How to execute livestreamer command with cron?Python 'Import pyodbc' does not work in a cron taskWhy doesn't my cron work?Cron does literally nothingCron jobs got executed, but it does not show any results at destination databaseCannot run python script with cronScript in cron not working
The commands that runs by source
doesn’t work.
crontab -e
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
Content of cron file is 1
.
command-line cron
add a comment |
The commands that runs by source
doesn’t work.
crontab -e
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
Content of cron file is 1
.
command-line cron
add a comment |
The commands that runs by source
doesn’t work.
crontab -e
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
Content of cron file is 1
.
command-line cron
The commands that runs by source
doesn’t work.
crontab -e
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
Content of cron file is 1
.
command-line cron
command-line cron
edited 39 mins ago
dessert
24.1k670104
24.1k670104
asked 2 hours ago
ahmadahmad
8010
8010
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
source
is a bash
-ism (or zsh
-ism for that matter) whereas cron
uses sh
(dash
) by default as the shell of choice.
So you need to use .
instead of source
to remain POSIX:
. "$HOME"/.zshrc
Or you can change the shell to any shell you want by using the SHELL
variable of crontab
e.g.:
SHELL=/usr/bin/zsh
You need to put this near the top of crontab
, before any command entry.
Following your example:
SHELL=/usr/bin/zsh
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
And now you can stick with your original source
approach.
This is the recommended approach for your case as you're source
-ing .zshrc
, presumably you have zsh
specific declarations in there which won't work in sh
.
If you don't want to set the SHELL
variable, you can run the whole command as an argument to zsh -c
, but this incurs careful quoting.
A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh
shebang or as an argument to zsh
(without making it executable).
As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.
I'd normally agree with sticking to/bin/sh
- but given the OP is trying to source.zshrc
they may well need to set the shell tozsh
– steeldriver
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
|
show 4 more comments
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%2f1120930%2fmy-cron-command-doesn-t-work%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
source
is a bash
-ism (or zsh
-ism for that matter) whereas cron
uses sh
(dash
) by default as the shell of choice.
So you need to use .
instead of source
to remain POSIX:
. "$HOME"/.zshrc
Or you can change the shell to any shell you want by using the SHELL
variable of crontab
e.g.:
SHELL=/usr/bin/zsh
You need to put this near the top of crontab
, before any command entry.
Following your example:
SHELL=/usr/bin/zsh
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
And now you can stick with your original source
approach.
This is the recommended approach for your case as you're source
-ing .zshrc
, presumably you have zsh
specific declarations in there which won't work in sh
.
If you don't want to set the SHELL
variable, you can run the whole command as an argument to zsh -c
, but this incurs careful quoting.
A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh
shebang or as an argument to zsh
(without making it executable).
As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.
I'd normally agree with sticking to/bin/sh
- but given the OP is trying to source.zshrc
they may well need to set the shell tozsh
– steeldriver
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
|
show 4 more comments
source
is a bash
-ism (or zsh
-ism for that matter) whereas cron
uses sh
(dash
) by default as the shell of choice.
So you need to use .
instead of source
to remain POSIX:
. "$HOME"/.zshrc
Or you can change the shell to any shell you want by using the SHELL
variable of crontab
e.g.:
SHELL=/usr/bin/zsh
You need to put this near the top of crontab
, before any command entry.
Following your example:
SHELL=/usr/bin/zsh
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
And now you can stick with your original source
approach.
This is the recommended approach for your case as you're source
-ing .zshrc
, presumably you have zsh
specific declarations in there which won't work in sh
.
If you don't want to set the SHELL
variable, you can run the whole command as an argument to zsh -c
, but this incurs careful quoting.
A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh
shebang or as an argument to zsh
(without making it executable).
As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.
I'd normally agree with sticking to/bin/sh
- but given the OP is trying to source.zshrc
they may well need to set the shell tozsh
– steeldriver
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
|
show 4 more comments
source
is a bash
-ism (or zsh
-ism for that matter) whereas cron
uses sh
(dash
) by default as the shell of choice.
So you need to use .
instead of source
to remain POSIX:
. "$HOME"/.zshrc
Or you can change the shell to any shell you want by using the SHELL
variable of crontab
e.g.:
SHELL=/usr/bin/zsh
You need to put this near the top of crontab
, before any command entry.
Following your example:
SHELL=/usr/bin/zsh
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
And now you can stick with your original source
approach.
This is the recommended approach for your case as you're source
-ing .zshrc
, presumably you have zsh
specific declarations in there which won't work in sh
.
If you don't want to set the SHELL
variable, you can run the whole command as an argument to zsh -c
, but this incurs careful quoting.
A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh
shebang or as an argument to zsh
(without making it executable).
As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.
source
is a bash
-ism (or zsh
-ism for that matter) whereas cron
uses sh
(dash
) by default as the shell of choice.
So you need to use .
instead of source
to remain POSIX:
. "$HOME"/.zshrc
Or you can change the shell to any shell you want by using the SHELL
variable of crontab
e.g.:
SHELL=/usr/bin/zsh
You need to put this near the top of crontab
, before any command entry.
Following your example:
SHELL=/usr/bin/zsh
*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron
And now you can stick with your original source
approach.
This is the recommended approach for your case as you're source
-ing .zshrc
, presumably you have zsh
specific declarations in there which won't work in sh
.
If you don't want to set the SHELL
variable, you can run the whole command as an argument to zsh -c
, but this incurs careful quoting.
A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh
shebang or as an argument to zsh
(without making it executable).
As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.
edited 1 hour ago
answered 2 hours ago
heemaylheemayl
67.1k9142214
67.1k9142214
I'd normally agree with sticking to/bin/sh
- but given the OP is trying to source.zshrc
they may well need to set the shell tozsh
– steeldriver
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
|
show 4 more comments
I'd normally agree with sticking to/bin/sh
- but given the OP is trying to source.zshrc
they may well need to set the shell tozsh
– steeldriver
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
I'd normally agree with sticking to
/bin/sh
- but given the OP is trying to source .zshrc
they may well need to set the shell to zsh
– steeldriver
1 hour ago
I'd normally agree with sticking to
/bin/sh
- but given the OP is trying to source .zshrc
they may well need to set the shell to zsh
– steeldriver
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2
– ahmad
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@steeldriver Fair call. Edited.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@ahmad Check my edits.
– heemayl
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
@steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(
– ahmad
1 hour ago
|
show 4 more comments
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%2f1120930%2fmy-cron-command-doesn-t-work%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