Skip to main content
clarity?
Source Link
Seamus
  • 3.8k
  • 2
  • 21
  • 48

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

$ sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontabuser crontab will actually work (e.g. Raspberry Pi OS). UsingHowever, using the root crontab is a more portable approachapproach; it also eliminates the need to use sudo to run any command or script. So, if you used sudo mount 'blah, blah' in a user crontab, it becomes mount 'blah, blah' in the root crontab.

If you're curious about - or wish to make changes to -you don't know what the environment is for jobs run under cron, you can addask cron to tell you by adding this entry to the root crontab (sudo crontab -e):

0 12 * * * /usr/bin/printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.

And finally, see this Q&A for how to change the environment in cron.

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontab will actually work (e.g. Raspberry Pi OS). Using the root crontab is a more portable approach.

If you're curious about - or wish to make changes to - the environment, you can add this entry to the root crontab (sudo crontab -e):

0 12 * * * /usr/bin/printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

$ sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontab will actually work (e.g. Raspberry Pi OS). However, using the root crontab is a more portable approach; it also eliminates the need to use sudo to run any command or script. So, if you used sudo mount 'blah, blah' in a user crontab, it becomes mount 'blah, blah' in the root crontab.

If you don't know what the environment is for jobs run under cron, you can ask cron to tell you by adding this entry to the root crontab (sudo crontab -e):

0 12 * * * /usr/bin/printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.

And finally, see this Q&A for how to change the environment in cron.

added 9 characters in body
Source Link
Seamus
  • 3.8k
  • 2
  • 21
  • 48

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontab will actually work (e.g. Raspberry Pi OS). Using the root crontab is a more portable approach.

If you're curious about - or wish to make changes to - the environment, you can add this entry to the root crontab (sudo crontab -e):

0 12 * * * /usr/bin/printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontab will actually work (e.g. Raspberry Pi OS). Using the root crontab is a more portable approach.

If you're curious about - or wish to make changes to - the environment, you can add this entry to the root crontab (sudo crontab -e):

0 12 * * * printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontab will actually work (e.g. Raspberry Pi OS). Using the root crontab is a more portable approach.

If you're curious about - or wish to make changes to - the environment, you can add this entry to the root crontab (sudo crontab -e):

0 12 * * * /usr/bin/printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.

Source Link
Seamus
  • 3.8k
  • 2
  • 21
  • 48

A bit late, and probably no longer of interest to the OP, but for others who may be struggling with the use of sudo in a user crontab, here's a potential solution:

Instead of using sudo in a user crontab, use the root crontab:

sudo crontab -e

In some systems - depending on how sudo is configured - using sudo in a user crontab will actually work (e.g. Raspberry Pi OS). Using the root crontab is a more portable approach.

If you're curious about - or wish to make changes to - the environment, you can add this entry to the root crontab (sudo crontab -e):

0 12 * * * printenv > /home/user_me/cronenvironment_sudo.txt 2>&1

Change user_me to an actual username on your system, and see the crontab guru for help with the schedule.