Run local user cronjob as root

The name of the pictureThe name of the pictureThe name of the pictureClash 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...




  1. Adding the job to my user crontab (crontab -e) and setting the user as root...



    17 10 * * * root /etc/cron.daily/cammedia.sh



  2. Adding 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?







share|improve this question


















  • 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










  • 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










  • 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














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...




  1. Adding the job to my user crontab (crontab -e) and setting the user as root...



    17 10 * * * root /etc/cron.daily/cammedia.sh



  2. Adding 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?







share|improve this question


















  • 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










  • 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










  • 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












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...




  1. Adding the job to my user crontab (crontab -e) and setting the user as root...



    17 10 * * * root /etc/cron.daily/cammedia.sh



  2. Adding 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?







share|improve this question














I'm attempting to run a cron job as root user, but it will not execute. Here's what I've tried...




  1. Adding the job to my user crontab (crontab -e) and setting the user as root...



    17 10 * * * root /etc/cron.daily/cammedia.sh



  2. Adding 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?









share|improve this question













share|improve this question




share|improve this question








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 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










  • 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










  • @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




    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










  • 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










  • @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










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.






share|improve this answer






















  • 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











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',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • 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















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.






share|improve this answer






















  • 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













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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













 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

GRUB: Fatal! inconsistent data read from (0x84) 0+xxxxxx

Do not install recommended packages of dependencies

What makes Checkinstall packages not suitable for distribution?