shell script is not executed after adding it as a crontab jobWhy does my bash script output “+ '[' 0 -le 1 ']'” when started with bash -x script.sh?crontab command not runroot cron job not runningWhy the cron job did not fire on ubuntu 12.04?Why my cron Job does not work?Help, ubuntu server 14.04 crontab cannot run my database backup script, but other simple script is okCrontab script not runningRoot cron job not executing script properly. PATH or HOME directories the problem?Cron Script Not WorkingCron job,crontabsome crontab job not working , not all
Arriving at the same result with the opposite hypotheses
What was with Miles Morales's stickers?
Why only the fundamental frequency component is said to give useful power?
Implement Homestuck's Catenative Doomsday Dice Cascader
How did they achieve the Gunslinger's shining eye effect in Westworld?
Can anyone identify this tank?
"You've got another thing coming" - translation into French
Trapping Rain Water
How did students remember what to practise between lessons without any sheet music?
What language is the software written in on the ISS?
No array bounds check when using auto
Can an Aarakocra use a shield while flying?
Is using haveibeenpwned to validate password strength rational?
Comparing and find out which feature has highest shape area in QGIS?
How powerful is a "Breathe Air" spell?
Find duplicated column value in CSV
Orange material in grout lines - need help to identify
Does setting a new type clear the rules text for non-lands?
Is open-sourcing the code of a webapp not recommended?
Is the term 'open source' a trademark?
Are there downsides to using std::string as a buffer?
Why would future John risk sending back a T-800 to save his younger self?
How do I write "Show, Don't Tell" as a person with Asperger Syndrome?
Was there a priest on the Titanic who stayed on the ship giving confession to as many as he could?
shell script is not executed after adding it as a crontab job
Why does my bash script output “+ '[' 0 -le 1 ']'” when started with bash -x script.sh?crontab command not runroot cron job not runningWhy the cron job did not fire on ubuntu 12.04?Why my cron Job does not work?Help, ubuntu server 14.04 crontab cannot run my database backup script, but other simple script is okCrontab script not runningRoot cron job not executing script properly. PATH or HOME directories the problem?Cron Script Not WorkingCron job,crontabsome crontab job not working , not all
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have added the following crontab job:
sudo crontab -e
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh
>/home/ubuntu/backup/log/backup.log
I have tried both root and ubuntu users.
When I run the command:
sudo crontab -l
And when I run:
systemctl status cron
But mysqlbackup.sh is not executed. Any idea what is the problem or how can I diagnose what is going wrong?
Note I have added only minutes to test the script
command-line bash cron
add a comment |
I have added the following crontab job:
sudo crontab -e
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh
>/home/ubuntu/backup/log/backup.log
I have tried both root and ubuntu users.
When I run the command:
sudo crontab -l
And when I run:
systemctl status cron
But mysqlbackup.sh is not executed. Any idea what is the problem or how can I diagnose what is going wrong?
Note I have added only minutes to test the script
command-line bash cron
2
Add at end of line:2>&1
This will also redirect stderr to same log file. Then check log for errors.
– LeonidMew
May 21 at 10:24
1
To see error messages you can usejournalctl -b | grep -i cron
– WinEunuuchs2Unix
May 21 at 10:37
1
Please don't add screen dumps of text. Copy and paste text and format it corretly.
– Soren A
May 21 at 10:49
@soren, ok thanks for letting me know.
– Hooman Bahreini
May 21 at 10:50
add a comment |
I have added the following crontab job:
sudo crontab -e
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh
>/home/ubuntu/backup/log/backup.log
I have tried both root and ubuntu users.
When I run the command:
sudo crontab -l
And when I run:
systemctl status cron
But mysqlbackup.sh is not executed. Any idea what is the problem or how can I diagnose what is going wrong?
Note I have added only minutes to test the script
command-line bash cron
I have added the following crontab job:
sudo crontab -e
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh
>/home/ubuntu/backup/log/backup.log
I have tried both root and ubuntu users.
When I run the command:
sudo crontab -l
And when I run:
systemctl status cron
But mysqlbackup.sh is not executed. Any idea what is the problem or how can I diagnose what is going wrong?
Note I have added only minutes to test the script
command-line bash cron
command-line bash cron
edited May 21 at 10:22
Hooman Bahreini
asked May 21 at 10:17
Hooman BahreiniHooman Bahreini
1747
1747
2
Add at end of line:2>&1
This will also redirect stderr to same log file. Then check log for errors.
– LeonidMew
May 21 at 10:24
1
To see error messages you can usejournalctl -b | grep -i cron
– WinEunuuchs2Unix
May 21 at 10:37
1
Please don't add screen dumps of text. Copy and paste text and format it corretly.
– Soren A
May 21 at 10:49
@soren, ok thanks for letting me know.
– Hooman Bahreini
May 21 at 10:50
add a comment |
2
Add at end of line:2>&1
This will also redirect stderr to same log file. Then check log for errors.
– LeonidMew
May 21 at 10:24
1
To see error messages you can usejournalctl -b | grep -i cron
– WinEunuuchs2Unix
May 21 at 10:37
1
Please don't add screen dumps of text. Copy and paste text and format it corretly.
– Soren A
May 21 at 10:49
@soren, ok thanks for letting me know.
– Hooman Bahreini
May 21 at 10:50
2
2
Add at end of line:
2>&1
This will also redirect stderr to same log file. Then check log for errors.– LeonidMew
May 21 at 10:24
Add at end of line:
2>&1
This will also redirect stderr to same log file. Then check log for errors.– LeonidMew
May 21 at 10:24
1
1
To see error messages you can use
journalctl -b | grep -i cron
– WinEunuuchs2Unix
May 21 at 10:37
To see error messages you can use
journalctl -b | grep -i cron
– WinEunuuchs2Unix
May 21 at 10:37
1
1
Please don't add screen dumps of text. Copy and paste text and format it corretly.
– Soren A
May 21 at 10:49
Please don't add screen dumps of text. Copy and paste text and format it corretly.
– Soren A
May 21 at 10:49
@soren, ok thanks for letting me know.
– Hooman Bahreini
May 21 at 10:50
@soren, ok thanks for letting me know.
– Hooman Bahreini
May 21 at 10:50
add a comment |
1 Answer
1
active
oldest
votes
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
This is incorrect format.
The format is described in the crontab file:
# m h dom mon dow command
ubuntu
is not a command. Remove it, so the line reads:
58 * * * * /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
Systemwide crontab, specified in /etc/crontab
has the user field:
These files also have username fields,
# that none of the other crontabs do.
[...]
# m h dom mon dow user command
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
2
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. runcrontab -e
as the user in question. The editor shows you the correct format, complete with examples.
– vidarlo
May 21 at 10:35
4
+1 the user field is an extra field that is only used in system-wide crontabs (/etc/crontab
and files in/etc/cron.d/
)
– steeldriver
May 21 at 10:40
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2faskubuntu.com%2fquestions%2f1145001%2fshell-script-is-not-executed-after-adding-it-as-a-crontab-job%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
This is incorrect format.
The format is described in the crontab file:
# m h dom mon dow command
ubuntu
is not a command. Remove it, so the line reads:
58 * * * * /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
Systemwide crontab, specified in /etc/crontab
has the user field:
These files also have username fields,
# that none of the other crontabs do.
[...]
# m h dom mon dow user command
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
2
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. runcrontab -e
as the user in question. The editor shows you the correct format, complete with examples.
– vidarlo
May 21 at 10:35
4
+1 the user field is an extra field that is only used in system-wide crontabs (/etc/crontab
and files in/etc/cron.d/
)
– steeldriver
May 21 at 10:40
add a comment |
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
This is incorrect format.
The format is described in the crontab file:
# m h dom mon dow command
ubuntu
is not a command. Remove it, so the line reads:
58 * * * * /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
Systemwide crontab, specified in /etc/crontab
has the user field:
These files also have username fields,
# that none of the other crontabs do.
[...]
# m h dom mon dow user command
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
2
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. runcrontab -e
as the user in question. The editor shows you the correct format, complete with examples.
– vidarlo
May 21 at 10:35
4
+1 the user field is an extra field that is only used in system-wide crontabs (/etc/crontab
and files in/etc/cron.d/
)
– steeldriver
May 21 at 10:40
add a comment |
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
This is incorrect format.
The format is described in the crontab file:
# m h dom mon dow command
ubuntu
is not a command. Remove it, so the line reads:
58 * * * * /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
Systemwide crontab, specified in /etc/crontab
has the user field:
These files also have username fields,
# that none of the other crontabs do.
[...]
# m h dom mon dow user command
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
This is incorrect format.
The format is described in the crontab file:
# m h dom mon dow command
ubuntu
is not a command. Remove it, so the line reads:
58 * * * * /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log
Systemwide crontab, specified in /etc/crontab
has the user field:
These files also have username fields,
# that none of the other crontabs do.
[...]
# m h dom mon dow user command
edited May 21 at 10:47
answered May 21 at 10:31
vidarlovidarlo
11.6k53054
11.6k53054
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
2
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. runcrontab -e
as the user in question. The editor shows you the correct format, complete with examples.
– vidarlo
May 21 at 10:35
4
+1 the user field is an extra field that is only used in system-wide crontabs (/etc/crontab
and files in/etc/cron.d/
)
– steeldriver
May 21 at 10:40
add a comment |
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
2
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. runcrontab -e
as the user in question. The editor shows you the correct format, complete with examples.
– vidarlo
May 21 at 10:35
4
+1 the user field is an extra field that is only used in system-wide crontabs (/etc/crontab
and files in/etc/cron.d/
)
– steeldriver
May 21 at 10:40
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
Thanks... should I not add the user?
– Hooman Bahreini
May 21 at 10:34
2
2
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. run
crontab -e
as the user in question. The editor shows you the correct format, complete with examples.– vidarlo
May 21 at 10:35
No, if you want to run it as a specific user, you should add it to that users crontab, e.g. run
crontab -e
as the user in question. The editor shows you the correct format, complete with examples.– vidarlo
May 21 at 10:35
4
4
+1 the user field is an extra field that is only used in system-wide crontabs (
/etc/crontab
and files in /etc/cron.d/
)– steeldriver
May 21 at 10:40
+1 the user field is an extra field that is only used in system-wide crontabs (
/etc/crontab
and files in /etc/cron.d/
)– steeldriver
May 21 at 10:40
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1145001%2fshell-script-is-not-executed-after-adding-it-as-a-crontab-job%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
2
Add at end of line:
2>&1
This will also redirect stderr to same log file. Then check log for errors.– LeonidMew
May 21 at 10:24
1
To see error messages you can use
journalctl -b | grep -i cron
– WinEunuuchs2Unix
May 21 at 10:37
1
Please don't add screen dumps of text. Copy and paste text and format it corretly.
– Soren A
May 21 at 10:49
@soren, ok thanks for letting me know.
– Hooman Bahreini
May 21 at 10:50