Run local user cronjob as root

Clash Royale CLAN TAG#URR8PPP up vote
2
down vote
favorite
I'm attempting to run a cron job as root user, but it will not execute. Here's what I've tried...
Adding the job to my user crontab (crontab -e) and setting the user as root...
17 10 * * * root /etc/cron.daily/cammedia.shAdding the job to the root user crontab (sudo crontab -e) and also adding the a few PATH's...
PATH=/usr/sbin:/usr/bin:/sbin:/bin
PATH=/usr/sbin:/usr/bin:/sbin:/etc
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/scott
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc
#
0 4 * * * /etc/cron.daily/cammedia.sh
Here's the result of running crontab -l (local user account) after a test run:
May 26 10:17:01 WEBCAM CRON[89901]: (scott) CMD (root /etc/cron.daily/cammedia.sh)
May 26 10:17:01 WEBCAM CRON[89902]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
May 26 10:17:01 WEBCAM CRON[89900]: (CRON) info (No MTA installed, discarding output)
Suggestions?
cron
 |Â
show 3 more comments
up vote
2
down vote
favorite
I'm attempting to run a cron job as root user, but it will not execute. Here's what I've tried...
Adding the job to my user crontab (crontab -e) and setting the user as root...
17 10 * * * root /etc/cron.daily/cammedia.shAdding the job to the root user crontab (sudo crontab -e) and also adding the a few PATH's...
PATH=/usr/sbin:/usr/bin:/sbin:/bin
PATH=/usr/sbin:/usr/bin:/sbin:/etc
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/scott
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc
#
0 4 * * * /etc/cron.daily/cammedia.sh
Here's the result of running crontab -l (local user account) after a test run:
May 26 10:17:01 WEBCAM CRON[89901]: (scott) CMD (root /etc/cron.daily/cammedia.sh)
May 26 10:17:01 WEBCAM CRON[89902]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
May 26 10:17:01 WEBCAM CRON[89900]: (CRON) info (No MTA installed, discarding output)
Suggestions?
cron
2
User crontabs (i.e. those invoked usingcrontab -eorsudo crontab -ein the case ofroot) do not support an additional field to specify the user - that's only valid in the system-wide crontab file/etc/crontab. Seeman 5 crontabfor discussion of the differences.
â steeldriver
May 26 at 17:26
Please tell us when (at what time, at what interval) you want yourcammedia.shto be executed.
â PerlDuck
May 26 at 17:28
Related: How to set up an hourly Cron job to rungrivefrom/etc/cron.hourly?
â steeldriver
May 26 at 17:34
Thanks @steeldriver. How then, do I get my user script to run as root, assuming it needs to be run as root? Also, I didn't gain anything from the link you presented, sorry.
â Scott
May 27 at 15:37
@PerlDuck, I want to run this everyday, though the specific time is not really important; for example-sake, let's say run it @ 10:17 every AM.
â Scott
May 27 at 15:39
 |Â
show 3 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm attempting to run a cron job as root user, but it will not execute. Here's what I've tried...
Adding the job to my user crontab (crontab -e) and setting the user as root...
17 10 * * * root /etc/cron.daily/cammedia.shAdding the job to the root user crontab (sudo crontab -e) and also adding the a few PATH's...
PATH=/usr/sbin:/usr/bin:/sbin:/bin
PATH=/usr/sbin:/usr/bin:/sbin:/etc
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/scott
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc
#
0 4 * * * /etc/cron.daily/cammedia.sh
Here's the result of running crontab -l (local user account) after a test run:
May 26 10:17:01 WEBCAM CRON[89901]: (scott) CMD (root /etc/cron.daily/cammedia.sh)
May 26 10:17:01 WEBCAM CRON[89902]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
May 26 10:17:01 WEBCAM CRON[89900]: (CRON) info (No MTA installed, discarding output)
Suggestions?
cron
I'm attempting to run a cron job as root user, but it will not execute. Here's what I've tried...
Adding the job to my user crontab (crontab -e) and setting the user as root...
17 10 * * * root /etc/cron.daily/cammedia.shAdding the job to the root user crontab (sudo crontab -e) and also adding the a few PATH's...
PATH=/usr/sbin:/usr/bin:/sbin:/bin
PATH=/usr/sbin:/usr/bin:/sbin:/etc
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/scott
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc
#
0 4 * * * /etc/cron.daily/cammedia.sh
Here's the result of running crontab -l (local user account) after a test run:
May 26 10:17:01 WEBCAM CRON[89901]: (scott) CMD (root /etc/cron.daily/cammedia.sh)
May 26 10:17:01 WEBCAM CRON[89902]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
May 26 10:17:01 WEBCAM CRON[89900]: (CRON) info (No MTA installed, discarding output)
Suggestions?
cron
edited May 26 at 17:02
PerlDuck
3,62911030
3,62911030
asked May 26 at 16:56
Scott
133
133
2
User crontabs (i.e. those invoked usingcrontab -eorsudo crontab -ein the case ofroot) do not support an additional field to specify the user - that's only valid in the system-wide crontab file/etc/crontab. Seeman 5 crontabfor discussion of the differences.
â steeldriver
May 26 at 17:26
Please tell us when (at what time, at what interval) you want yourcammedia.shto be executed.
â PerlDuck
May 26 at 17:28
Related: How to set up an hourly Cron job to rungrivefrom/etc/cron.hourly?
â steeldriver
May 26 at 17:34
Thanks @steeldriver. How then, do I get my user script to run as root, assuming it needs to be run as root? Also, I didn't gain anything from the link you presented, sorry.
â Scott
May 27 at 15:37
@PerlDuck, I want to run this everyday, though the specific time is not really important; for example-sake, let's say run it @ 10:17 every AM.
â Scott
May 27 at 15:39
 |Â
show 3 more comments
2
User crontabs (i.e. those invoked usingcrontab -eorsudo crontab -ein the case ofroot) do not support an additional field to specify the user - that's only valid in the system-wide crontab file/etc/crontab. Seeman 5 crontabfor discussion of the differences.
â steeldriver
May 26 at 17:26
Please tell us when (at what time, at what interval) you want yourcammedia.shto be executed.
â PerlDuck
May 26 at 17:28
Related: How to set up an hourly Cron job to rungrivefrom/etc/cron.hourly?
â steeldriver
May 26 at 17:34
Thanks @steeldriver. How then, do I get my user script to run as root, assuming it needs to be run as root? Also, I didn't gain anything from the link you presented, sorry.
â Scott
May 27 at 15:37
@PerlDuck, I want to run this everyday, though the specific time is not really important; for example-sake, let's say run it @ 10:17 every AM.
â Scott
May 27 at 15:39
2
2
User crontabs (i.e. those invoked using
crontab -e or sudo crontab -e in the case of root) do not support an additional field to specify the user - that's only valid in the system-wide crontab file /etc/crontab. See man 5 crontab for discussion of the differences.â steeldriver
May 26 at 17:26
User crontabs (i.e. those invoked using
crontab -e or sudo crontab -e in the case of root) do not support an additional field to specify the user - that's only valid in the system-wide crontab file /etc/crontab. See man 5 crontab for discussion of the differences.â steeldriver
May 26 at 17:26
Please tell us when (at what time, at what interval) you want your
cammedia.sh to be executed.â PerlDuck
May 26 at 17:28
Please tell us when (at what time, at what interval) you want your
cammedia.sh to be executed.â PerlDuck
May 26 at 17:28
Related: How to set up an hourly Cron job to run
grive from /etc/cron.hourly?â steeldriver
May 26 at 17:34
Related: How to set up an hourly Cron job to run
grive from /etc/cron.hourly?â steeldriver
May 26 at 17:34
Thanks @steeldriver. How then, do I get my user script to run as root, assuming it needs to be run as root? Also, I didn't gain anything from the link you presented, sorry.
â Scott
May 27 at 15:37
Thanks @steeldriver. How then, do I get my user script to run as root, assuming it needs to be run as root? Also, I didn't gain anything from the link you presented, sorry.
â Scott
May 27 at 15:37
@PerlDuck, I want to run this everyday, though the specific time is not really important; for example-sake, let's say run it @ 10:17 every AM.
â Scott
May 27 at 15:39
@PerlDuck, I want to run this everyday, though the specific time is not really important; for example-sake, let's say run it @ 10:17 every AM.
â Scott
May 27 at 15:39
 |Â
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
Just remove the line completely. Simply placing a script in /etc/cron.daily will already make it run once a day. You will have to rename it to not contain the .sh suffix to be suitable for the cron.daily directory.
If you do not want to run it at the default time for cron.daily you should store the script elsewhere, e. g. /usr/local/bin/cammedia.sh.
If you plan to do this you should be aware that only root can run cron jobs as another user, for normal users it is not valid.
Do not forget to make the script executable by running chmod +x cammedia.sh in any case.
The output of the script will be e-mailed to you. If that is not possible (and according to the logs in your question it is not), the output will be discarded. There are other ways to get the output. E. g. you could add the following statement to the cammedia script:
logger "cammedia script run"
and you should see something in syslog.
A good read on the subject is https://help.ubuntu.com/community/CronHowto, it will help you get your problem solved.
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Just remove the line completely. Simply placing a script in /etc/cron.daily will already make it run once a day. You will have to rename it to not contain the .sh suffix to be suitable for the cron.daily directory.
If you do not want to run it at the default time for cron.daily you should store the script elsewhere, e. g. /usr/local/bin/cammedia.sh.
If you plan to do this you should be aware that only root can run cron jobs as another user, for normal users it is not valid.
Do not forget to make the script executable by running chmod +x cammedia.sh in any case.
The output of the script will be e-mailed to you. If that is not possible (and according to the logs in your question it is not), the output will be discarded. There are other ways to get the output. E. g. you could add the following statement to the cammedia script:
logger "cammedia script run"
and you should see something in syslog.
A good read on the subject is https://help.ubuntu.com/community/CronHowto, it will help you get your problem solved.
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
add a comment |Â
up vote
5
down vote
accepted
Just remove the line completely. Simply placing a script in /etc/cron.daily will already make it run once a day. You will have to rename it to not contain the .sh suffix to be suitable for the cron.daily directory.
If you do not want to run it at the default time for cron.daily you should store the script elsewhere, e. g. /usr/local/bin/cammedia.sh.
If you plan to do this you should be aware that only root can run cron jobs as another user, for normal users it is not valid.
Do not forget to make the script executable by running chmod +x cammedia.sh in any case.
The output of the script will be e-mailed to you. If that is not possible (and according to the logs in your question it is not), the output will be discarded. There are other ways to get the output. E. g. you could add the following statement to the cammedia script:
logger "cammedia script run"
and you should see something in syslog.
A good read on the subject is https://help.ubuntu.com/community/CronHowto, it will help you get your problem solved.
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Just remove the line completely. Simply placing a script in /etc/cron.daily will already make it run once a day. You will have to rename it to not contain the .sh suffix to be suitable for the cron.daily directory.
If you do not want to run it at the default time for cron.daily you should store the script elsewhere, e. g. /usr/local/bin/cammedia.sh.
If you plan to do this you should be aware that only root can run cron jobs as another user, for normal users it is not valid.
Do not forget to make the script executable by running chmod +x cammedia.sh in any case.
The output of the script will be e-mailed to you. If that is not possible (and according to the logs in your question it is not), the output will be discarded. There are other ways to get the output. E. g. you could add the following statement to the cammedia script:
logger "cammedia script run"
and you should see something in syslog.
A good read on the subject is https://help.ubuntu.com/community/CronHowto, it will help you get your problem solved.
Just remove the line completely. Simply placing a script in /etc/cron.daily will already make it run once a day. You will have to rename it to not contain the .sh suffix to be suitable for the cron.daily directory.
If you do not want to run it at the default time for cron.daily you should store the script elsewhere, e. g. /usr/local/bin/cammedia.sh.
If you plan to do this you should be aware that only root can run cron jobs as another user, for normal users it is not valid.
Do not forget to make the script executable by running chmod +x cammedia.sh in any case.
The output of the script will be e-mailed to you. If that is not possible (and according to the logs in your question it is not), the output will be discarded. There are other ways to get the output. E. g. you could add the following statement to the cammedia script:
logger "cammedia script run"
and you should see something in syslog.
A good read on the subject is https://help.ubuntu.com/community/CronHowto, it will help you get your problem solved.
edited May 27 at 17:44
answered May 26 at 17:20
Sebastian Stark
4,603838
4,603838
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
add a comment |Â
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
Thanks, @Sebastian, though I cannot get it to run simply by having it placed in the cron.daily folder. I removed the .sh extension, and I set & verifed 777 permissions on the file. The script functions perfectly if run independently. When I run 'grep CRON /var/log/syslog`, my script is not shown to have executed.
â Scott
May 27 at 15:33
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1040645%2frun-local-user-cronjob-as-root%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
2
User crontabs (i.e. those invoked using
crontab -eorsudo crontab -ein the case ofroot) do not support an additional field to specify the user - that's only valid in the system-wide crontab file/etc/crontab. Seeman 5 crontabfor discussion of the differences.â steeldriver
May 26 at 17:26
Please tell us when (at what time, at what interval) you want your
cammedia.shto be executed.â PerlDuck
May 26 at 17:28
Related: How to set up an hourly Cron job to run
grivefrom/etc/cron.hourly?â steeldriver
May 26 at 17:34
Thanks @steeldriver. How then, do I get my user script to run as root, assuming it needs to be run as root? Also, I didn't gain anything from the link you presented, sorry.
â Scott
May 27 at 15:37
@PerlDuck, I want to run this everyday, though the specific time is not really important; for example-sake, let's say run it @ 10:17 every AM.
â Scott
May 27 at 15:39