Crontab tasks aren't running
up vote
2
down vote
favorite
I tried created a very simple cron task that echo's "Hello World" into a file named /tmp/example.txt
.
You can see from the screenshot, I tried:
28 23 * * * echo "Hello World" >> /tmp/example.txt
28 23 * * * root /bin/bash echo "Hello World" >> /tmp/example.txt
Also in the screenshot, you can see the date. I have also tried getting the exact date in the cron task (e.g.: 28 23 29 11 4), but that didn't work either.
I also tried using an actual file
28 23 * * * ./pingstuff
The pingstuff file just pings Google. I can run this file and it executes properly. But, when I try using it in the crontab -e, nothing happens at the scheduled time. (Times have been changed accordingly after each attempt.)
I am logged in as a super user. I have permissions to read/write/execute all of these files. I'm not really sure what I'm doing wrong.
linux bash cron
New contributor
add a comment |
up vote
2
down vote
favorite
I tried created a very simple cron task that echo's "Hello World" into a file named /tmp/example.txt
.
You can see from the screenshot, I tried:
28 23 * * * echo "Hello World" >> /tmp/example.txt
28 23 * * * root /bin/bash echo "Hello World" >> /tmp/example.txt
Also in the screenshot, you can see the date. I have also tried getting the exact date in the cron task (e.g.: 28 23 29 11 4), but that didn't work either.
I also tried using an actual file
28 23 * * * ./pingstuff
The pingstuff file just pings Google. I can run this file and it executes properly. But, when I try using it in the crontab -e, nothing happens at the scheduled time. (Times have been changed accordingly after each attempt.)
I am logged in as a super user. I have permissions to read/write/execute all of these files. I'm not really sure what I'm doing wrong.
linux bash cron
New contributor
1
What Linux distribution are you using? Is your cron daemon enabled and started?
– n.st
3 hours ago
Also, when you're testing crontabs, set an execution time that's more than one minute in the future. Some (but not all) cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a34 12 …
cronjob at 12:33:30.
– n.st
3 hours ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I tried created a very simple cron task that echo's "Hello World" into a file named /tmp/example.txt
.
You can see from the screenshot, I tried:
28 23 * * * echo "Hello World" >> /tmp/example.txt
28 23 * * * root /bin/bash echo "Hello World" >> /tmp/example.txt
Also in the screenshot, you can see the date. I have also tried getting the exact date in the cron task (e.g.: 28 23 29 11 4), but that didn't work either.
I also tried using an actual file
28 23 * * * ./pingstuff
The pingstuff file just pings Google. I can run this file and it executes properly. But, when I try using it in the crontab -e, nothing happens at the scheduled time. (Times have been changed accordingly after each attempt.)
I am logged in as a super user. I have permissions to read/write/execute all of these files. I'm not really sure what I'm doing wrong.
linux bash cron
New contributor
I tried created a very simple cron task that echo's "Hello World" into a file named /tmp/example.txt
.
You can see from the screenshot, I tried:
28 23 * * * echo "Hello World" >> /tmp/example.txt
28 23 * * * root /bin/bash echo "Hello World" >> /tmp/example.txt
Also in the screenshot, you can see the date. I have also tried getting the exact date in the cron task (e.g.: 28 23 29 11 4), but that didn't work either.
I also tried using an actual file
28 23 * * * ./pingstuff
The pingstuff file just pings Google. I can run this file and it executes properly. But, when I try using it in the crontab -e, nothing happens at the scheduled time. (Times have been changed accordingly after each attempt.)
I am logged in as a super user. I have permissions to read/write/execute all of these files. I'm not really sure what I'm doing wrong.
linux bash cron
linux bash cron
New contributor
New contributor
edited 2 hours ago
Rui F Ribeiro
38.3k1475127
38.3k1475127
New contributor
asked 3 hours ago
Pixii Bomb
111
111
New contributor
New contributor
1
What Linux distribution are you using? Is your cron daemon enabled and started?
– n.st
3 hours ago
Also, when you're testing crontabs, set an execution time that's more than one minute in the future. Some (but not all) cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a34 12 …
cronjob at 12:33:30.
– n.st
3 hours ago
add a comment |
1
What Linux distribution are you using? Is your cron daemon enabled and started?
– n.st
3 hours ago
Also, when you're testing crontabs, set an execution time that's more than one minute in the future. Some (but not all) cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a34 12 …
cronjob at 12:33:30.
– n.st
3 hours ago
1
1
What Linux distribution are you using? Is your cron daemon enabled and started?
– n.st
3 hours ago
What Linux distribution are you using? Is your cron daemon enabled and started?
– n.st
3 hours ago
Also, when you're testing crontabs, set an execution time that's more than one minute in the future. Some (but not all) cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a
34 12 …
cronjob at 12:33:30.– n.st
3 hours ago
Also, when you're testing crontabs, set an execution time that's more than one minute in the future. Some (but not all) cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a
34 12 …
cronjob at 12:33:30.– n.st
3 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
A cronjob may fail to execute because
- the cron daemon is not running
- there's a syntax error in the crontab
- there's a syntax error in the command
- or there's a permission problem (e.g. execute bit not set)
To check if the daemon is running, try service cron status
or systemctl status cron
(the service manager depends on your distribution). The daemon may also be called something slightly different, like crond
or cronie
.
If it's not running, start it (replace status
with start
).
If it's running, proceed to check the relevant log files to see whether the job was actually run. Depending on your distribution, this might be logged to /var/log/syslog
, /var/log/messages
, a daemon-specific file like /var/log/cron
, or a systemd binary log file (journalctl -u cron
to view). You should see a line for each execution of the job.
When testing crontabs, set an execution time that's more than one minute in the future. Some cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a 34 12 …
cronjob at 12:33:30.
If the job runs but doesn't produce the expected result, try running the command from the crontab manually, as the same user, with the same shell (usually the minimalistic /bin/sh
).
One common pitfall (though not the case here) are %
characters in the command: they are treated specially by cron and need to be escaped (%
) to be seen by the actual command invocation.
Most cron implementations also send the output (if any) of each cronjob as an email. If you haven't set up mail delivery over the internet, those mails should be stored locally and be readable using the mail
command.
Several good points.
– G-Man
2 hours ago
add a comment |
up vote
2
down vote
Your biggest problem is that /bin/bash echo "Hello World"
is not a valid command.
It looks for a script called echo
.
Try /bin/bash -c 'echo "Hello World"'
instead.
The second problem is that you should specify an absolute pathname
for pingstuff
.
A third issue that caught my eye is that /tmp/example.txt
already exists (the cat
command didn't get an error message).
Are you sure that you have write permission to it?
(Of course, that shouldn't be an issue if you're running as root.)
See also Ubuntu 14.04, 16.04, 18.04 Cron job doesn't execute,
although it probably isn't related.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
A cronjob may fail to execute because
- the cron daemon is not running
- there's a syntax error in the crontab
- there's a syntax error in the command
- or there's a permission problem (e.g. execute bit not set)
To check if the daemon is running, try service cron status
or systemctl status cron
(the service manager depends on your distribution). The daemon may also be called something slightly different, like crond
or cronie
.
If it's not running, start it (replace status
with start
).
If it's running, proceed to check the relevant log files to see whether the job was actually run. Depending on your distribution, this might be logged to /var/log/syslog
, /var/log/messages
, a daemon-specific file like /var/log/cron
, or a systemd binary log file (journalctl -u cron
to view). You should see a line for each execution of the job.
When testing crontabs, set an execution time that's more than one minute in the future. Some cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a 34 12 …
cronjob at 12:33:30.
If the job runs but doesn't produce the expected result, try running the command from the crontab manually, as the same user, with the same shell (usually the minimalistic /bin/sh
).
One common pitfall (though not the case here) are %
characters in the command: they are treated specially by cron and need to be escaped (%
) to be seen by the actual command invocation.
Most cron implementations also send the output (if any) of each cronjob as an email. If you haven't set up mail delivery over the internet, those mails should be stored locally and be readable using the mail
command.
Several good points.
– G-Man
2 hours ago
add a comment |
up vote
5
down vote
A cronjob may fail to execute because
- the cron daemon is not running
- there's a syntax error in the crontab
- there's a syntax error in the command
- or there's a permission problem (e.g. execute bit not set)
To check if the daemon is running, try service cron status
or systemctl status cron
(the service manager depends on your distribution). The daemon may also be called something slightly different, like crond
or cronie
.
If it's not running, start it (replace status
with start
).
If it's running, proceed to check the relevant log files to see whether the job was actually run. Depending on your distribution, this might be logged to /var/log/syslog
, /var/log/messages
, a daemon-specific file like /var/log/cron
, or a systemd binary log file (journalctl -u cron
to view). You should see a line for each execution of the job.
When testing crontabs, set an execution time that's more than one minute in the future. Some cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a 34 12 …
cronjob at 12:33:30.
If the job runs but doesn't produce the expected result, try running the command from the crontab manually, as the same user, with the same shell (usually the minimalistic /bin/sh
).
One common pitfall (though not the case here) are %
characters in the command: they are treated specially by cron and need to be escaped (%
) to be seen by the actual command invocation.
Most cron implementations also send the output (if any) of each cronjob as an email. If you haven't set up mail delivery over the internet, those mails should be stored locally and be readable using the mail
command.
Several good points.
– G-Man
2 hours ago
add a comment |
up vote
5
down vote
up vote
5
down vote
A cronjob may fail to execute because
- the cron daemon is not running
- there's a syntax error in the crontab
- there's a syntax error in the command
- or there's a permission problem (e.g. execute bit not set)
To check if the daemon is running, try service cron status
or systemctl status cron
(the service manager depends on your distribution). The daemon may also be called something slightly different, like crond
or cronie
.
If it's not running, start it (replace status
with start
).
If it's running, proceed to check the relevant log files to see whether the job was actually run. Depending on your distribution, this might be logged to /var/log/syslog
, /var/log/messages
, a daemon-specific file like /var/log/cron
, or a systemd binary log file (journalctl -u cron
to view). You should see a line for each execution of the job.
When testing crontabs, set an execution time that's more than one minute in the future. Some cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a 34 12 …
cronjob at 12:33:30.
If the job runs but doesn't produce the expected result, try running the command from the crontab manually, as the same user, with the same shell (usually the minimalistic /bin/sh
).
One common pitfall (though not the case here) are %
characters in the command: they are treated specially by cron and need to be escaped (%
) to be seen by the actual command invocation.
Most cron implementations also send the output (if any) of each cronjob as an email. If you haven't set up mail delivery over the internet, those mails should be stored locally and be readable using the mail
command.
A cronjob may fail to execute because
- the cron daemon is not running
- there's a syntax error in the crontab
- there's a syntax error in the command
- or there's a permission problem (e.g. execute bit not set)
To check if the daemon is running, try service cron status
or systemctl status cron
(the service manager depends on your distribution). The daemon may also be called something slightly different, like crond
or cronie
.
If it's not running, start it (replace status
with start
).
If it's running, proceed to check the relevant log files to see whether the job was actually run. Depending on your distribution, this might be logged to /var/log/syslog
, /var/log/messages
, a daemon-specific file like /var/log/cron
, or a systemd binary log file (journalctl -u cron
to view). You should see a line for each execution of the job.
When testing crontabs, set an execution time that's more than one minute in the future. Some cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a 34 12 …
cronjob at 12:33:30.
If the job runs but doesn't produce the expected result, try running the command from the crontab manually, as the same user, with the same shell (usually the minimalistic /bin/sh
).
One common pitfall (though not the case here) are %
characters in the command: they are treated specially by cron and need to be escaped (%
) to be seen by the actual command invocation.
Most cron implementations also send the output (if any) of each cronjob as an email. If you haven't set up mail delivery over the internet, those mails should be stored locally and be readable using the mail
command.
edited 2 hours ago
answered 2 hours ago
n.st
5,04311741
5,04311741
Several good points.
– G-Man
2 hours ago
add a comment |
Several good points.
– G-Man
2 hours ago
Several good points.
– G-Man
2 hours ago
Several good points.
– G-Man
2 hours ago
add a comment |
up vote
2
down vote
Your biggest problem is that /bin/bash echo "Hello World"
is not a valid command.
It looks for a script called echo
.
Try /bin/bash -c 'echo "Hello World"'
instead.
The second problem is that you should specify an absolute pathname
for pingstuff
.
A third issue that caught my eye is that /tmp/example.txt
already exists (the cat
command didn't get an error message).
Are you sure that you have write permission to it?
(Of course, that shouldn't be an issue if you're running as root.)
See also Ubuntu 14.04, 16.04, 18.04 Cron job doesn't execute,
although it probably isn't related.
add a comment |
up vote
2
down vote
Your biggest problem is that /bin/bash echo "Hello World"
is not a valid command.
It looks for a script called echo
.
Try /bin/bash -c 'echo "Hello World"'
instead.
The second problem is that you should specify an absolute pathname
for pingstuff
.
A third issue that caught my eye is that /tmp/example.txt
already exists (the cat
command didn't get an error message).
Are you sure that you have write permission to it?
(Of course, that shouldn't be an issue if you're running as root.)
See also Ubuntu 14.04, 16.04, 18.04 Cron job doesn't execute,
although it probably isn't related.
add a comment |
up vote
2
down vote
up vote
2
down vote
Your biggest problem is that /bin/bash echo "Hello World"
is not a valid command.
It looks for a script called echo
.
Try /bin/bash -c 'echo "Hello World"'
instead.
The second problem is that you should specify an absolute pathname
for pingstuff
.
A third issue that caught my eye is that /tmp/example.txt
already exists (the cat
command didn't get an error message).
Are you sure that you have write permission to it?
(Of course, that shouldn't be an issue if you're running as root.)
See also Ubuntu 14.04, 16.04, 18.04 Cron job doesn't execute,
although it probably isn't related.
Your biggest problem is that /bin/bash echo "Hello World"
is not a valid command.
It looks for a script called echo
.
Try /bin/bash -c 'echo "Hello World"'
instead.
The second problem is that you should specify an absolute pathname
for pingstuff
.
A third issue that caught my eye is that /tmp/example.txt
already exists (the cat
command didn't get an error message).
Are you sure that you have write permission to it?
(Of course, that shouldn't be an issue if you're running as root.)
See also Ubuntu 14.04, 16.04, 18.04 Cron job doesn't execute,
although it probably isn't related.
edited 2 hours ago
answered 3 hours ago
G-Man
12.3k92961
12.3k92961
add a comment |
add a comment |
Pixii Bomb is a new contributor. Be nice, and check out our Code of Conduct.
Pixii Bomb is a new contributor. Be nice, and check out our Code of Conduct.
Pixii Bomb is a new contributor. Be nice, and check out our Code of Conduct.
Pixii Bomb is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2funix.stackexchange.com%2fquestions%2f485065%2fcrontab-tasks-arent-running%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
1
What Linux distribution are you using? Is your cron daemon enabled and started?
– n.st
3 hours ago
Also, when you're testing crontabs, set an execution time that's more than one minute in the future. Some (but not all) cron implementations "pre-plan" what tasks to run, i.e. they'll decide at 12:33:00 what to run at 12:34:00, so you'll miss the window of opportunity if you add a
34 12 …
cronjob at 12:33:30.– n.st
3 hours ago