What is the environment for cron?Default shell for cron issueWhere do Cron error message go?Addition to cron is not executedRun transmission through cronCron running 2hrs earlyifconfig don't work with cronCron for Raspberry PiCron not call sh scriptRaspberry Cron don't workCron doesnt run specific .py file
Is there a korbon needed for conversion?
What happens if you roll doubles 3 times then land on "Go to jail?"
Roman Numeral Treatment of Suspensions
Anatomically Correct Strange Women In Ponds Distributing Swords
What can we do to stop prior company from asking us questions?
Sort a list by elements of another list
Would this custom Sorcerer variant that can only learn any verbal-component-only spell be unbalanced?
Integer addition + constant, is it a group?
Crossing the line between justified force and brutality
Are student evaluations of teaching assistants read by others in the faculty?
CREATE opcode: what does it really do?
How do I find the solutions of the following equation?
How does it work when somebody invests in my business?
Pre-amplifier input protection
Why are there no referendums in the US?
How can I kill an app using Terminal?
Do the temporary hit points from the Battlerager barbarian's Reckless Abandon stack if I make multiple attacks on my turn?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Go Pregnant or Go Home
Avoiding estate tax by giving multiple gifts
What is the opposite of 'gravitas'?
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
How do I go from 300 unfinished/half written blog posts, to published posts?
What does the word "Atten" mean?
What is the environment for cron?
Default shell for cron issueWhere do Cron error message go?Addition to cron is not executedRun transmission through cronCron running 2hrs earlyifconfig don't work with cronCron for Raspberry PiCron not call sh scriptRaspberry Cron don't workCron doesnt run specific .py file
When issues arise using cron
to schedule events, a frequently-heard explanation is that cron
runs with a different set of environment variables than a "normal" user (e.g. pi
). That's all well and good, but what is the environment for the cron
user? If one is to avoid errors due to an incorrect environment when using cron
, it would be useful to know what that environment is.
cron
add a comment |
When issues arise using cron
to schedule events, a frequently-heard explanation is that cron
runs with a different set of environment variables than a "normal" user (e.g. pi
). That's all well and good, but what is the environment for the cron
user? If one is to avoid errors due to an incorrect environment when using cron
, it would be useful to know what that environment is.
cron
add a comment |
When issues arise using cron
to schedule events, a frequently-heard explanation is that cron
runs with a different set of environment variables than a "normal" user (e.g. pi
). That's all well and good, but what is the environment for the cron
user? If one is to avoid errors due to an incorrect environment when using cron
, it would be useful to know what that environment is.
cron
When issues arise using cron
to schedule events, a frequently-heard explanation is that cron
runs with a different set of environment variables than a "normal" user (e.g. pi
). That's all well and good, but what is the environment for the cron
user? If one is to avoid errors due to an incorrect environment when using cron
, it would be useful to know what that environment is.
cron
cron
asked yesterday


SeamusSeamus
2,8501321
2,8501321
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
We can ask cron
to tell us what its environment is.
- Create a shell script in your home directory (
~/
) as follows (or with the editor of your choice):
$ nano ~/envtst.sh
- Enter/C+P the following in the editor:
#!/bin/sh
echo "env report follows for user "$USER >> /home/pi/envtst.sh.out
env >> /home/pi/envtst.sh.out
echo "env report for user "$USER" concluded" >> /home/pi/envtst.sh.out
echo " " >> /home/pi/envtst.sh.out
- Save the file and exit the editor; then set the file permissions as executable, and open your
crontab
for editing:
$ chmod a+rx ~/envtst.sh
$ crontab -e
- Enter the following line at the bottom of your
crontab
:
* * * * * /home/pi/envtst.sh >> /home/pi/envtst.sh.err 2>&1
- Save and exit your
crontab
. Usetail
to view the output & (hopefully) observe the environment forcron
. If there's nothing in the file after a minute, view the file~/envtst.sh.err
for error messages, and adjust as required. (NOTE: If you want to clear all prior error messages after troubleshooting:$ > ~/envtst.sh.err
)
crontab: installing new crontab
$ tail -f ~/envtst.sh.out
env report follows for user
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/pi
env report for user concluded
This will repeat every minute, so enter ^C
to stop the tail
listing, edit your crontab
again to "comment out" (or delete) the line just added. Save and exit the editor.
Note in the
tail
output above thatcron
has a rather sparse environment; only six (6) variables are used to define it. Note thePATH
consists of only two directories. This is why your crontab entry fails if, for example, you're trying to launch a Python script that resides in your home directory. Note also that the user name (aka LOGNAME iaw System V) isn'tcron
- it'spi
!If you're not familiar, with your own user environment, it's useful to compare it against the
cron
environment. We'll use the same shell script to add that to the "output" file~/envtst.sh.out
:
$ ~/envtst.sh
$
- To view the output, open
~/envtst.sh.out
in your editor, orcat ~/envtst.sh.out
to see it in your terminal. It will likely be a fairly extensive output; 30 lines of text, more or less. Note in particular the following lines (assuming you've run this as userpi
) :
USER=pi
...
HOME=/home/pi
LOGNAME=pi
_=/home/pi/envtst.sh
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
...
SHELL=/bin/bash
- You'll notice numerous differences in the two environments. This will help create rational
cron
jobs, and help troubleshooting when they don't behave as you'd like.
Very nice! For some reason your$USER
variable isn't set -- seeenv report for user concluded
.
– Mark Smith
yesterday
@MarkSmith: If you're referring to the absence of $USER in thecron
environment, it's not that it's not set... it's just not used in the version ofcron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined forcron
in any Raspbian distro
– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P
– Seamus
yesterday
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("schematics", function ()
StackExchange.schematics.init();
);
, "cicuitlab");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "447"
;
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
);
);
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%2fraspberrypi.stackexchange.com%2fquestions%2f95799%2fwhat-is-the-environment-for-cron%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
We can ask cron
to tell us what its environment is.
- Create a shell script in your home directory (
~/
) as follows (or with the editor of your choice):
$ nano ~/envtst.sh
- Enter/C+P the following in the editor:
#!/bin/sh
echo "env report follows for user "$USER >> /home/pi/envtst.sh.out
env >> /home/pi/envtst.sh.out
echo "env report for user "$USER" concluded" >> /home/pi/envtst.sh.out
echo " " >> /home/pi/envtst.sh.out
- Save the file and exit the editor; then set the file permissions as executable, and open your
crontab
for editing:
$ chmod a+rx ~/envtst.sh
$ crontab -e
- Enter the following line at the bottom of your
crontab
:
* * * * * /home/pi/envtst.sh >> /home/pi/envtst.sh.err 2>&1
- Save and exit your
crontab
. Usetail
to view the output & (hopefully) observe the environment forcron
. If there's nothing in the file after a minute, view the file~/envtst.sh.err
for error messages, and adjust as required. (NOTE: If you want to clear all prior error messages after troubleshooting:$ > ~/envtst.sh.err
)
crontab: installing new crontab
$ tail -f ~/envtst.sh.out
env report follows for user
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/pi
env report for user concluded
This will repeat every minute, so enter ^C
to stop the tail
listing, edit your crontab
again to "comment out" (or delete) the line just added. Save and exit the editor.
Note in the
tail
output above thatcron
has a rather sparse environment; only six (6) variables are used to define it. Note thePATH
consists of only two directories. This is why your crontab entry fails if, for example, you're trying to launch a Python script that resides in your home directory. Note also that the user name (aka LOGNAME iaw System V) isn'tcron
- it'spi
!If you're not familiar, with your own user environment, it's useful to compare it against the
cron
environment. We'll use the same shell script to add that to the "output" file~/envtst.sh.out
:
$ ~/envtst.sh
$
- To view the output, open
~/envtst.sh.out
in your editor, orcat ~/envtst.sh.out
to see it in your terminal. It will likely be a fairly extensive output; 30 lines of text, more or less. Note in particular the following lines (assuming you've run this as userpi
) :
USER=pi
...
HOME=/home/pi
LOGNAME=pi
_=/home/pi/envtst.sh
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
...
SHELL=/bin/bash
- You'll notice numerous differences in the two environments. This will help create rational
cron
jobs, and help troubleshooting when they don't behave as you'd like.
Very nice! For some reason your$USER
variable isn't set -- seeenv report for user concluded
.
– Mark Smith
yesterday
@MarkSmith: If you're referring to the absence of $USER in thecron
environment, it's not that it's not set... it's just not used in the version ofcron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined forcron
in any Raspbian distro
– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P
– Seamus
yesterday
add a comment |
We can ask cron
to tell us what its environment is.
- Create a shell script in your home directory (
~/
) as follows (or with the editor of your choice):
$ nano ~/envtst.sh
- Enter/C+P the following in the editor:
#!/bin/sh
echo "env report follows for user "$USER >> /home/pi/envtst.sh.out
env >> /home/pi/envtst.sh.out
echo "env report for user "$USER" concluded" >> /home/pi/envtst.sh.out
echo " " >> /home/pi/envtst.sh.out
- Save the file and exit the editor; then set the file permissions as executable, and open your
crontab
for editing:
$ chmod a+rx ~/envtst.sh
$ crontab -e
- Enter the following line at the bottom of your
crontab
:
* * * * * /home/pi/envtst.sh >> /home/pi/envtst.sh.err 2>&1
- Save and exit your
crontab
. Usetail
to view the output & (hopefully) observe the environment forcron
. If there's nothing in the file after a minute, view the file~/envtst.sh.err
for error messages, and adjust as required. (NOTE: If you want to clear all prior error messages after troubleshooting:$ > ~/envtst.sh.err
)
crontab: installing new crontab
$ tail -f ~/envtst.sh.out
env report follows for user
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/pi
env report for user concluded
This will repeat every minute, so enter ^C
to stop the tail
listing, edit your crontab
again to "comment out" (or delete) the line just added. Save and exit the editor.
Note in the
tail
output above thatcron
has a rather sparse environment; only six (6) variables are used to define it. Note thePATH
consists of only two directories. This is why your crontab entry fails if, for example, you're trying to launch a Python script that resides in your home directory. Note also that the user name (aka LOGNAME iaw System V) isn'tcron
- it'spi
!If you're not familiar, with your own user environment, it's useful to compare it against the
cron
environment. We'll use the same shell script to add that to the "output" file~/envtst.sh.out
:
$ ~/envtst.sh
$
- To view the output, open
~/envtst.sh.out
in your editor, orcat ~/envtst.sh.out
to see it in your terminal. It will likely be a fairly extensive output; 30 lines of text, more or less. Note in particular the following lines (assuming you've run this as userpi
) :
USER=pi
...
HOME=/home/pi
LOGNAME=pi
_=/home/pi/envtst.sh
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
...
SHELL=/bin/bash
- You'll notice numerous differences in the two environments. This will help create rational
cron
jobs, and help troubleshooting when they don't behave as you'd like.
Very nice! For some reason your$USER
variable isn't set -- seeenv report for user concluded
.
– Mark Smith
yesterday
@MarkSmith: If you're referring to the absence of $USER in thecron
environment, it's not that it's not set... it's just not used in the version ofcron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined forcron
in any Raspbian distro
– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P
– Seamus
yesterday
add a comment |
We can ask cron
to tell us what its environment is.
- Create a shell script in your home directory (
~/
) as follows (or with the editor of your choice):
$ nano ~/envtst.sh
- Enter/C+P the following in the editor:
#!/bin/sh
echo "env report follows for user "$USER >> /home/pi/envtst.sh.out
env >> /home/pi/envtst.sh.out
echo "env report for user "$USER" concluded" >> /home/pi/envtst.sh.out
echo " " >> /home/pi/envtst.sh.out
- Save the file and exit the editor; then set the file permissions as executable, and open your
crontab
for editing:
$ chmod a+rx ~/envtst.sh
$ crontab -e
- Enter the following line at the bottom of your
crontab
:
* * * * * /home/pi/envtst.sh >> /home/pi/envtst.sh.err 2>&1
- Save and exit your
crontab
. Usetail
to view the output & (hopefully) observe the environment forcron
. If there's nothing in the file after a minute, view the file~/envtst.sh.err
for error messages, and adjust as required. (NOTE: If you want to clear all prior error messages after troubleshooting:$ > ~/envtst.sh.err
)
crontab: installing new crontab
$ tail -f ~/envtst.sh.out
env report follows for user
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/pi
env report for user concluded
This will repeat every minute, so enter ^C
to stop the tail
listing, edit your crontab
again to "comment out" (or delete) the line just added. Save and exit the editor.
Note in the
tail
output above thatcron
has a rather sparse environment; only six (6) variables are used to define it. Note thePATH
consists of only two directories. This is why your crontab entry fails if, for example, you're trying to launch a Python script that resides in your home directory. Note also that the user name (aka LOGNAME iaw System V) isn'tcron
- it'spi
!If you're not familiar, with your own user environment, it's useful to compare it against the
cron
environment. We'll use the same shell script to add that to the "output" file~/envtst.sh.out
:
$ ~/envtst.sh
$
- To view the output, open
~/envtst.sh.out
in your editor, orcat ~/envtst.sh.out
to see it in your terminal. It will likely be a fairly extensive output; 30 lines of text, more or less. Note in particular the following lines (assuming you've run this as userpi
) :
USER=pi
...
HOME=/home/pi
LOGNAME=pi
_=/home/pi/envtst.sh
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
...
SHELL=/bin/bash
- You'll notice numerous differences in the two environments. This will help create rational
cron
jobs, and help troubleshooting when they don't behave as you'd like.
We can ask cron
to tell us what its environment is.
- Create a shell script in your home directory (
~/
) as follows (or with the editor of your choice):
$ nano ~/envtst.sh
- Enter/C+P the following in the editor:
#!/bin/sh
echo "env report follows for user "$USER >> /home/pi/envtst.sh.out
env >> /home/pi/envtst.sh.out
echo "env report for user "$USER" concluded" >> /home/pi/envtst.sh.out
echo " " >> /home/pi/envtst.sh.out
- Save the file and exit the editor; then set the file permissions as executable, and open your
crontab
for editing:
$ chmod a+rx ~/envtst.sh
$ crontab -e
- Enter the following line at the bottom of your
crontab
:
* * * * * /home/pi/envtst.sh >> /home/pi/envtst.sh.err 2>&1
- Save and exit your
crontab
. Usetail
to view the output & (hopefully) observe the environment forcron
. If there's nothing in the file after a minute, view the file~/envtst.sh.err
for error messages, and adjust as required. (NOTE: If you want to clear all prior error messages after troubleshooting:$ > ~/envtst.sh.err
)
crontab: installing new crontab
$ tail -f ~/envtst.sh.out
env report follows for user
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/pi
env report for user concluded
This will repeat every minute, so enter ^C
to stop the tail
listing, edit your crontab
again to "comment out" (or delete) the line just added. Save and exit the editor.
Note in the
tail
output above thatcron
has a rather sparse environment; only six (6) variables are used to define it. Note thePATH
consists of only two directories. This is why your crontab entry fails if, for example, you're trying to launch a Python script that resides in your home directory. Note also that the user name (aka LOGNAME iaw System V) isn'tcron
- it'spi
!If you're not familiar, with your own user environment, it's useful to compare it against the
cron
environment. We'll use the same shell script to add that to the "output" file~/envtst.sh.out
:
$ ~/envtst.sh
$
- To view the output, open
~/envtst.sh.out
in your editor, orcat ~/envtst.sh.out
to see it in your terminal. It will likely be a fairly extensive output; 30 lines of text, more or less. Note in particular the following lines (assuming you've run this as userpi
) :
USER=pi
...
HOME=/home/pi
LOGNAME=pi
_=/home/pi/envtst.sh
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
...
SHELL=/bin/bash
- You'll notice numerous differences in the two environments. This will help create rational
cron
jobs, and help troubleshooting when they don't behave as you'd like.
edited yesterday
answered yesterday


SeamusSeamus
2,8501321
2,8501321
Very nice! For some reason your$USER
variable isn't set -- seeenv report for user concluded
.
– Mark Smith
yesterday
@MarkSmith: If you're referring to the absence of $USER in thecron
environment, it's not that it's not set... it's just not used in the version ofcron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined forcron
in any Raspbian distro
– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P
– Seamus
yesterday
add a comment |
Very nice! For some reason your$USER
variable isn't set -- seeenv report for user concluded
.
– Mark Smith
yesterday
@MarkSmith: If you're referring to the absence of $USER in thecron
environment, it's not that it's not set... it's just not used in the version ofcron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined forcron
in any Raspbian distro
– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P
– Seamus
yesterday
Very nice! For some reason your
$USER
variable isn't set -- see env report for user concluded
.– Mark Smith
yesterday
Very nice! For some reason your
$USER
variable isn't set -- see env report for user concluded
.– Mark Smith
yesterday
@MarkSmith: If you're referring to the absence of $USER in the
cron
environment, it's not that it's not set... it's just not used in the version of cron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined for cron
in any Raspbian distro– Seamus
yesterday
@MarkSmith: If you're referring to the absence of $USER in the
cron
environment, it's not that it's not set... it's just not used in the version of cron
on Raspbian (and Debian I think). Here's some more on that, and still more, and more. Likely more to this story, but I don't think $USER defined for cron
in any Raspbian distro– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:
env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P– Seamus
yesterday
@MarkSmith: It just dawned on me the line you referenced:
env report for user concluded
. Yeah... :) I stuck that in the script to emphasize that $USER isn't defined :P– Seamus
yesterday
add a comment |
Thanks for contributing an answer to Raspberry Pi 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%2fraspberrypi.stackexchange.com%2fquestions%2f95799%2fwhat-is-the-environment-for-cron%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