Issues getting crontab to work.
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.
I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:
#!/bin/bash
echo "I work"
I log into terminal as root (sudo -i) and am entering:
sudo bash /home/lskidson/tests/script.sh
It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)
* * * * * sudo bash /home/lskidson/tests/script.sh
I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.
Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!
scripts cron
add a comment |Â
up vote
0
down vote
favorite
Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.
I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:
#!/bin/bash
echo "I work"
I log into terminal as root (sudo -i) and am entering:
sudo bash /home/lskidson/tests/script.sh
It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)
* * * * * sudo bash /home/lskidson/tests/script.sh
I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.
Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!
scripts cron
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.
I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:
#!/bin/bash
echo "I work"
I log into terminal as root (sudo -i) and am entering:
sudo bash /home/lskidson/tests/script.sh
It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)
* * * * * sudo bash /home/lskidson/tests/script.sh
I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.
Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!
scripts cron
Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.
I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:
#!/bin/bash
echo "I work"
I log into terminal as root (sudo -i) and am entering:
sudo bash /home/lskidson/tests/script.sh
It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)
* * * * * sudo bash /home/lskidson/tests/script.sh
I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.
Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!
scripts cron
scripts cron
asked Mar 22 at 16:10
LSKidson
33
33
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.
Pipe your output to file like so
echo "I work" > /path/to/some/file.txt
or
* * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt
Use > to overwrite the file, >> to append to it.
add a comment |Â
up vote
1
down vote
Firs with the shebang #!/bin/bash
you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash
in from of it:
chmod +x /home/lskidson/tests/script.sh
In general the command sudo
is not applicable within crontab
. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e
.
Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.
1. If the executable file generates an output file, or just modifies some things, the Cron job should be:
* * * * * /home/lskidson/tests/script.sh
2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1
redirects and the error messages to stdout):
* * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1
3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO
in crontab
:
MAILTO="my@custom.mail"
* * * * * /home/lskidson/tests/script.sh
References:
- How to detect error in cron jobs
How do I make cron create cron.log?
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.
Pipe your output to file like so
echo "I work" > /path/to/some/file.txt
or
* * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt
Use > to overwrite the file, >> to append to it.
add a comment |Â
up vote
1
down vote
accepted
How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.
Pipe your output to file like so
echo "I work" > /path/to/some/file.txt
or
* * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt
Use > to overwrite the file, >> to append to it.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.
Pipe your output to file like so
echo "I work" > /path/to/some/file.txt
or
* * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt
Use > to overwrite the file, >> to append to it.
How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.
Pipe your output to file like so
echo "I work" > /path/to/some/file.txt
or
* * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt
Use > to overwrite the file, >> to append to it.
answered Mar 22 at 16:38
rtaft
397111
397111
add a comment |Â
add a comment |Â
up vote
1
down vote
Firs with the shebang #!/bin/bash
you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash
in from of it:
chmod +x /home/lskidson/tests/script.sh
In general the command sudo
is not applicable within crontab
. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e
.
Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.
1. If the executable file generates an output file, or just modifies some things, the Cron job should be:
* * * * * /home/lskidson/tests/script.sh
2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1
redirects and the error messages to stdout):
* * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1
3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO
in crontab
:
MAILTO="my@custom.mail"
* * * * * /home/lskidson/tests/script.sh
References:
- How to detect error in cron jobs
How do I make cron create cron.log?
add a comment |Â
up vote
1
down vote
Firs with the shebang #!/bin/bash
you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash
in from of it:
chmod +x /home/lskidson/tests/script.sh
In general the command sudo
is not applicable within crontab
. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e
.
Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.
1. If the executable file generates an output file, or just modifies some things, the Cron job should be:
* * * * * /home/lskidson/tests/script.sh
2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1
redirects and the error messages to stdout):
* * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1
3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO
in crontab
:
MAILTO="my@custom.mail"
* * * * * /home/lskidson/tests/script.sh
References:
- How to detect error in cron jobs
How do I make cron create cron.log?
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Firs with the shebang #!/bin/bash
you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash
in from of it:
chmod +x /home/lskidson/tests/script.sh
In general the command sudo
is not applicable within crontab
. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e
.
Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.
1. If the executable file generates an output file, or just modifies some things, the Cron job should be:
* * * * * /home/lskidson/tests/script.sh
2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1
redirects and the error messages to stdout):
* * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1
3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO
in crontab
:
MAILTO="my@custom.mail"
* * * * * /home/lskidson/tests/script.sh
References:
- How to detect error in cron jobs
How do I make cron create cron.log?
Firs with the shebang #!/bin/bash
you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash
in from of it:
chmod +x /home/lskidson/tests/script.sh
In general the command sudo
is not applicable within crontab
. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e
.
Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.
1. If the executable file generates an output file, or just modifies some things, the Cron job should be:
* * * * * /home/lskidson/tests/script.sh
2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1
redirects and the error messages to stdout):
* * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1
3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO
in crontab
:
MAILTO="my@custom.mail"
* * * * * /home/lskidson/tests/script.sh
References:
- How to detect error in cron jobs
How do I make cron create cron.log?
answered Mar 22 at 16:46
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12.3k52256
12.3k52256
add a comment |Â
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%2f1018296%2fissues-getting-crontab-to-work%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