Run crontab in specific day but only if is in specific weekday
I wanna run command with crontab in a specific day, but only if this day is not sunday.
I tried with this
1 0 27 12 1-6 command.sh
but the command run also wednesday december 26th.
How can I tell to crontab run command only the december 27th?
Thanks
Max
cron
add a comment |
I wanna run command with crontab in a specific day, but only if this day is not sunday.
I tried with this
1 0 27 12 1-6 command.sh
but the command run also wednesday december 26th.
How can I tell to crontab run command only the december 27th?
Thanks
Max
cron
You want the job to run on 27 but that day must not be a sunday but can be any other day!
– George Udosen
10 hours ago
Try this1 0 27 * 1-6
– George Udosen
10 hours ago
@GeorgeUdosen1 0 27 * 1-6
will run on every 27th plus every Mon…Sat. Cron's syntax is mean.
– PerlDuck
9 hours ago
add a comment |
I wanna run command with crontab in a specific day, but only if this day is not sunday.
I tried with this
1 0 27 12 1-6 command.sh
but the command run also wednesday december 26th.
How can I tell to crontab run command only the december 27th?
Thanks
Max
cron
I wanna run command with crontab in a specific day, but only if this day is not sunday.
I tried with this
1 0 27 12 1-6 command.sh
but the command run also wednesday december 26th.
How can I tell to crontab run command only the december 27th?
Thanks
Max
cron
cron
edited 11 hours ago
asked 11 hours ago
maxranzy
312
312
You want the job to run on 27 but that day must not be a sunday but can be any other day!
– George Udosen
10 hours ago
Try this1 0 27 * 1-6
– George Udosen
10 hours ago
@GeorgeUdosen1 0 27 * 1-6
will run on every 27th plus every Mon…Sat. Cron's syntax is mean.
– PerlDuck
9 hours ago
add a comment |
You want the job to run on 27 but that day must not be a sunday but can be any other day!
– George Udosen
10 hours ago
Try this1 0 27 * 1-6
– George Udosen
10 hours ago
@GeorgeUdosen1 0 27 * 1-6
will run on every 27th plus every Mon…Sat. Cron's syntax is mean.
– PerlDuck
9 hours ago
You want the job to run on 27 but that day must not be a sunday but can be any other day!
– George Udosen
10 hours ago
You want the job to run on 27 but that day must not be a sunday but can be any other day!
– George Udosen
10 hours ago
Try this
1 0 27 * 1-6
– George Udosen
10 hours ago
Try this
1 0 27 * 1-6
– George Udosen
10 hours ago
@GeorgeUdosen
1 0 27 * 1-6
will run on every 27th plus every Mon…Sat. Cron's syntax is mean.– PerlDuck
9 hours ago
@GeorgeUdosen
1 0 27 * 1-6
will run on every 27th plus every Mon…Sat. Cron's syntax is mean.– PerlDuck
9 hours ago
add a comment |
1 Answer
1
active
oldest
votes
I don't think it is possible with cron
alone because the syntax doesn't
allow for "at 27th except on Sundays". It only allows
for "either 27th or non-Sundays (or both)".
I suggest to either change command.sh
to immediately exit on non-Sundays
or put that check into the cronjob:
1 0 27 12 * test $(date +%u) -ne 7 && command.sh
At the shell, date +%u
returns the day of week (1…7, 1 is Monday). In
a cronjob we have to escape that %
sign (%
). The command will
check whether the current day is a non-Sunday and only then execute
command.sh
.
The cronjob will run on every Dec 27th at 00:01 o'clock,
no matter what day of the week that is, but only for non-Sundays the
command.sh
gets executed because the previous test only succeeds
for them.
Note: I sometimes use https://crontab.guru to check my cronjob's
timetables. It's quite handy.
Your definition translates to “At
00:01 on day-of-month 27 and on every day-of-week from Monday through
Saturday in December.” so it's quite the opposite of what you want.
From the manpage:
Note: The day of a command's execution can be specified by two fields
— day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the
current time. For example,30 4 1,15 * 5
would cause a command to
be run at 4:30 am on the 1st and 15th of each month, plus every
Friday. One can, however, achieve the desired result by adding a test
to the command (see the last example in EXAMPLE CRON FILE below).
…
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday"
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%2f1104605%2frun-crontab-in-specific-day-but-only-if-is-in-specific-weekday%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
I don't think it is possible with cron
alone because the syntax doesn't
allow for "at 27th except on Sundays". It only allows
for "either 27th or non-Sundays (or both)".
I suggest to either change command.sh
to immediately exit on non-Sundays
or put that check into the cronjob:
1 0 27 12 * test $(date +%u) -ne 7 && command.sh
At the shell, date +%u
returns the day of week (1…7, 1 is Monday). In
a cronjob we have to escape that %
sign (%
). The command will
check whether the current day is a non-Sunday and only then execute
command.sh
.
The cronjob will run on every Dec 27th at 00:01 o'clock,
no matter what day of the week that is, but only for non-Sundays the
command.sh
gets executed because the previous test only succeeds
for them.
Note: I sometimes use https://crontab.guru to check my cronjob's
timetables. It's quite handy.
Your definition translates to “At
00:01 on day-of-month 27 and on every day-of-week from Monday through
Saturday in December.” so it's quite the opposite of what you want.
From the manpage:
Note: The day of a command's execution can be specified by two fields
— day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the
current time. For example,30 4 1,15 * 5
would cause a command to
be run at 4:30 am on the 1st and 15th of each month, plus every
Friday. One can, however, achieve the desired result by adding a test
to the command (see the last example in EXAMPLE CRON FILE below).
…
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday"
add a comment |
I don't think it is possible with cron
alone because the syntax doesn't
allow for "at 27th except on Sundays". It only allows
for "either 27th or non-Sundays (or both)".
I suggest to either change command.sh
to immediately exit on non-Sundays
or put that check into the cronjob:
1 0 27 12 * test $(date +%u) -ne 7 && command.sh
At the shell, date +%u
returns the day of week (1…7, 1 is Monday). In
a cronjob we have to escape that %
sign (%
). The command will
check whether the current day is a non-Sunday and only then execute
command.sh
.
The cronjob will run on every Dec 27th at 00:01 o'clock,
no matter what day of the week that is, but only for non-Sundays the
command.sh
gets executed because the previous test only succeeds
for them.
Note: I sometimes use https://crontab.guru to check my cronjob's
timetables. It's quite handy.
Your definition translates to “At
00:01 on day-of-month 27 and on every day-of-week from Monday through
Saturday in December.” so it's quite the opposite of what you want.
From the manpage:
Note: The day of a command's execution can be specified by two fields
— day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the
current time. For example,30 4 1,15 * 5
would cause a command to
be run at 4:30 am on the 1st and 15th of each month, plus every
Friday. One can, however, achieve the desired result by adding a test
to the command (see the last example in EXAMPLE CRON FILE below).
…
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday"
add a comment |
I don't think it is possible with cron
alone because the syntax doesn't
allow for "at 27th except on Sundays". It only allows
for "either 27th or non-Sundays (or both)".
I suggest to either change command.sh
to immediately exit on non-Sundays
or put that check into the cronjob:
1 0 27 12 * test $(date +%u) -ne 7 && command.sh
At the shell, date +%u
returns the day of week (1…7, 1 is Monday). In
a cronjob we have to escape that %
sign (%
). The command will
check whether the current day is a non-Sunday and only then execute
command.sh
.
The cronjob will run on every Dec 27th at 00:01 o'clock,
no matter what day of the week that is, but only for non-Sundays the
command.sh
gets executed because the previous test only succeeds
for them.
Note: I sometimes use https://crontab.guru to check my cronjob's
timetables. It's quite handy.
Your definition translates to “At
00:01 on day-of-month 27 and on every day-of-week from Monday through
Saturday in December.” so it's quite the opposite of what you want.
From the manpage:
Note: The day of a command's execution can be specified by two fields
— day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the
current time. For example,30 4 1,15 * 5
would cause a command to
be run at 4:30 am on the 1st and 15th of each month, plus every
Friday. One can, however, achieve the desired result by adding a test
to the command (see the last example in EXAMPLE CRON FILE below).
…
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday"
I don't think it is possible with cron
alone because the syntax doesn't
allow for "at 27th except on Sundays". It only allows
for "either 27th or non-Sundays (or both)".
I suggest to either change command.sh
to immediately exit on non-Sundays
or put that check into the cronjob:
1 0 27 12 * test $(date +%u) -ne 7 && command.sh
At the shell, date +%u
returns the day of week (1…7, 1 is Monday). In
a cronjob we have to escape that %
sign (%
). The command will
check whether the current day is a non-Sunday and only then execute
command.sh
.
The cronjob will run on every Dec 27th at 00:01 o'clock,
no matter what day of the week that is, but only for non-Sundays the
command.sh
gets executed because the previous test only succeeds
for them.
Note: I sometimes use https://crontab.guru to check my cronjob's
timetables. It's quite handy.
Your definition translates to “At
00:01 on day-of-month 27 and on every day-of-week from Monday through
Saturday in December.” so it's quite the opposite of what you want.
From the manpage:
Note: The day of a command's execution can be specified by two fields
— day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the
current time. For example,30 4 1,15 * 5
would cause a command to
be run at 4:30 am on the 1st and 15th of each month, plus every
Friday. One can, however, achieve the desired result by adding a test
to the command (see the last example in EXAMPLE CRON FILE below).
…
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday"
edited 9 hours ago
answered 9 hours ago
PerlDuck
5,25911231
5,25911231
add a comment |
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.
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%2faskubuntu.com%2fquestions%2f1104605%2frun-crontab-in-specific-day-but-only-if-is-in-specific-weekday%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
You want the job to run on 27 but that day must not be a sunday but can be any other day!
– George Udosen
10 hours ago
Try this
1 0 27 * 1-6
– George Udosen
10 hours ago
@GeorgeUdosen
1 0 27 * 1-6
will run on every 27th plus every Mon…Sat. Cron's syntax is mean.– PerlDuck
9 hours ago