Run Script once a day with systemd
Clash Royale CLAN TAG#URR8PPP
I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?
cron backup systemd
add a comment |
I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?
cron backup systemd
3
I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days?
– Krzysztof Adamski
Sep 14 '12 at 18:29
Exactly. I will make a backup every day no matter how often I reboot my PC.
– Fu86
Sep 14 '12 at 22:42
5
If you're not hung up on systemd, this is exactly what anacron is for.
– Gilles
Sep 14 '12 at 23:48
I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete.
– Krzysztof Adamski
Sep 15 '12 at 9:16
That's right. That's why I'm currently using anacron and the good old at, with a daily job likeecho "obnam backup" | at "now + 10 minutes"
– Adrien Clerc
Sep 14 '13 at 10:33
add a comment |
I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?
cron backup systemd
I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?
cron backup systemd
cron backup systemd
asked Sep 14 '12 at 16:43
Fu86Fu86
22539
22539
3
I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days?
– Krzysztof Adamski
Sep 14 '12 at 18:29
Exactly. I will make a backup every day no matter how often I reboot my PC.
– Fu86
Sep 14 '12 at 22:42
5
If you're not hung up on systemd, this is exactly what anacron is for.
– Gilles
Sep 14 '12 at 23:48
I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete.
– Krzysztof Adamski
Sep 15 '12 at 9:16
That's right. That's why I'm currently using anacron and the good old at, with a daily job likeecho "obnam backup" | at "now + 10 minutes"
– Adrien Clerc
Sep 14 '13 at 10:33
add a comment |
3
I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days?
– Krzysztof Adamski
Sep 14 '12 at 18:29
Exactly. I will make a backup every day no matter how often I reboot my PC.
– Fu86
Sep 14 '12 at 22:42
5
If you're not hung up on systemd, this is exactly what anacron is for.
– Gilles
Sep 14 '12 at 23:48
I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete.
– Krzysztof Adamski
Sep 15 '12 at 9:16
That's right. That's why I'm currently using anacron and the good old at, with a daily job likeecho "obnam backup" | at "now + 10 minutes"
– Adrien Clerc
Sep 14 '13 at 10:33
3
3
I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days?
– Krzysztof Adamski
Sep 14 '12 at 18:29
I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days?
– Krzysztof Adamski
Sep 14 '12 at 18:29
Exactly. I will make a backup every day no matter how often I reboot my PC.
– Fu86
Sep 14 '12 at 22:42
Exactly. I will make a backup every day no matter how often I reboot my PC.
– Fu86
Sep 14 '12 at 22:42
5
5
If you're not hung up on systemd, this is exactly what anacron is for.
– Gilles
Sep 14 '12 at 23:48
If you're not hung up on systemd, this is exactly what anacron is for.
– Gilles
Sep 14 '12 at 23:48
I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete.
– Krzysztof Adamski
Sep 15 '12 at 9:16
I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete.
– Krzysztof Adamski
Sep 15 '12 at 9:16
That's right. That's why I'm currently using anacron and the good old at, with a daily job like
echo "obnam backup" | at "now + 10 minutes"
– Adrien Clerc
Sep 14 '13 at 10:33
That's right. That's why I'm currently using anacron and the good old at, with a daily job like
echo "obnam backup" | at "now + 10 minutes"
– Adrien Clerc
Sep 14 '13 at 10:33
add a comment |
4 Answers
4
active
oldest
votes
See: /lib/systemd/system/systemd-tmpfiles-clean.timer
:
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
This runs the corresponding .service
file 15 minutes after boot and then every day while the system is up. If you reboot multiple times in the same day, you can just have the backup script check the mtime of the archive and skip that run if it's less than a day old.
Also, if your backups are going to be heavy on IO, it might be helpful to read about the IOScheduling* directives in the systemd.exec(5) manpage.
add a comment |
I don't think it's possible to do this entirely in systemd as it does not track any state between reboots. You can easly schedule something to run 10 minutes after boot using systemd.timer
and its OnBootSec=
or OnStartupSec=
.
The script itself has to check if it was already run today or not. This can be easily implemented even in bash, for example:
#/bin/sh -x
FILE=/etc/lastrun
TODAY=`date +"%Y%m%d"`
LASTRUN=`cat $FILE`
[[ -z "$LASTRUN" ]] || [[ "$TODAY" -gt "$LASTRUN" ]] || exit
echo $TODAY > $FILE
RUNYOURSCRIPTHERE
add a comment |
Apparently this issue will be addressed in future releases. At least according to this email on the systemd-devel mailing list. Until that you have to go the hackish way Krzysztof proposed.
add a comment |
If you're not hung up on 10 min after boot, you can:
[Unit]
Description=...
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
OnCalendar=daily
makes it run every midnight, Persisten=true
on boot if there was at least one missed run.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f48203%2frun-script-once-a-day-with-systemd%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
See: /lib/systemd/system/systemd-tmpfiles-clean.timer
:
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
This runs the corresponding .service
file 15 minutes after boot and then every day while the system is up. If you reboot multiple times in the same day, you can just have the backup script check the mtime of the archive and skip that run if it's less than a day old.
Also, if your backups are going to be heavy on IO, it might be helpful to read about the IOScheduling* directives in the systemd.exec(5) manpage.
add a comment |
See: /lib/systemd/system/systemd-tmpfiles-clean.timer
:
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
This runs the corresponding .service
file 15 minutes after boot and then every day while the system is up. If you reboot multiple times in the same day, you can just have the backup script check the mtime of the archive and skip that run if it's less than a day old.
Also, if your backups are going to be heavy on IO, it might be helpful to read about the IOScheduling* directives in the systemd.exec(5) manpage.
add a comment |
See: /lib/systemd/system/systemd-tmpfiles-clean.timer
:
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
This runs the corresponding .service
file 15 minutes after boot and then every day while the system is up. If you reboot multiple times in the same day, you can just have the backup script check the mtime of the archive and skip that run if it's less than a day old.
Also, if your backups are going to be heavy on IO, it might be helpful to read about the IOScheduling* directives in the systemd.exec(5) manpage.
See: /lib/systemd/system/systemd-tmpfiles-clean.timer
:
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
This runs the corresponding .service
file 15 minutes after boot and then every day while the system is up. If you reboot multiple times in the same day, you can just have the backup script check the mtime of the archive and skip that run if it's less than a day old.
Also, if your backups are going to be heavy on IO, it might be helpful to read about the IOScheduling* directives in the systemd.exec(5) manpage.
edited Aug 25 '15 at 22:01
Evgeny Vereshchagin
3,25242236
3,25242236
answered Feb 8 '13 at 5:36
CraigCraig
9112
9112
add a comment |
add a comment |
I don't think it's possible to do this entirely in systemd as it does not track any state between reboots. You can easly schedule something to run 10 minutes after boot using systemd.timer
and its OnBootSec=
or OnStartupSec=
.
The script itself has to check if it was already run today or not. This can be easily implemented even in bash, for example:
#/bin/sh -x
FILE=/etc/lastrun
TODAY=`date +"%Y%m%d"`
LASTRUN=`cat $FILE`
[[ -z "$LASTRUN" ]] || [[ "$TODAY" -gt "$LASTRUN" ]] || exit
echo $TODAY > $FILE
RUNYOURSCRIPTHERE
add a comment |
I don't think it's possible to do this entirely in systemd as it does not track any state between reboots. You can easly schedule something to run 10 minutes after boot using systemd.timer
and its OnBootSec=
or OnStartupSec=
.
The script itself has to check if it was already run today or not. This can be easily implemented even in bash, for example:
#/bin/sh -x
FILE=/etc/lastrun
TODAY=`date +"%Y%m%d"`
LASTRUN=`cat $FILE`
[[ -z "$LASTRUN" ]] || [[ "$TODAY" -gt "$LASTRUN" ]] || exit
echo $TODAY > $FILE
RUNYOURSCRIPTHERE
add a comment |
I don't think it's possible to do this entirely in systemd as it does not track any state between reboots. You can easly schedule something to run 10 minutes after boot using systemd.timer
and its OnBootSec=
or OnStartupSec=
.
The script itself has to check if it was already run today or not. This can be easily implemented even in bash, for example:
#/bin/sh -x
FILE=/etc/lastrun
TODAY=`date +"%Y%m%d"`
LASTRUN=`cat $FILE`
[[ -z "$LASTRUN" ]] || [[ "$TODAY" -gt "$LASTRUN" ]] || exit
echo $TODAY > $FILE
RUNYOURSCRIPTHERE
I don't think it's possible to do this entirely in systemd as it does not track any state between reboots. You can easly schedule something to run 10 minutes after boot using systemd.timer
and its OnBootSec=
or OnStartupSec=
.
The script itself has to check if it was already run today or not. This can be easily implemented even in bash, for example:
#/bin/sh -x
FILE=/etc/lastrun
TODAY=`date +"%Y%m%d"`
LASTRUN=`cat $FILE`
[[ -z "$LASTRUN" ]] || [[ "$TODAY" -gt "$LASTRUN" ]] || exit
echo $TODAY > $FILE
RUNYOURSCRIPTHERE
answered Sep 15 '12 at 9:37
Krzysztof AdamskiKrzysztof Adamski
3,1781619
3,1781619
add a comment |
add a comment |
Apparently this issue will be addressed in future releases. At least according to this email on the systemd-devel mailing list. Until that you have to go the hackish way Krzysztof proposed.
add a comment |
Apparently this issue will be addressed in future releases. At least according to this email on the systemd-devel mailing list. Until that you have to go the hackish way Krzysztof proposed.
add a comment |
Apparently this issue will be addressed in future releases. At least according to this email on the systemd-devel mailing list. Until that you have to go the hackish way Krzysztof proposed.
Apparently this issue will be addressed in future releases. At least according to this email on the systemd-devel mailing list. Until that you have to go the hackish way Krzysztof proposed.
answered Jul 31 '13 at 2:47
mmhmmh
8915
8915
add a comment |
add a comment |
If you're not hung up on 10 min after boot, you can:
[Unit]
Description=...
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
OnCalendar=daily
makes it run every midnight, Persisten=true
on boot if there was at least one missed run.
add a comment |
If you're not hung up on 10 min after boot, you can:
[Unit]
Description=...
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
OnCalendar=daily
makes it run every midnight, Persisten=true
on boot if there was at least one missed run.
add a comment |
If you're not hung up on 10 min after boot, you can:
[Unit]
Description=...
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
OnCalendar=daily
makes it run every midnight, Persisten=true
on boot if there was at least one missed run.
If you're not hung up on 10 min after boot, you can:
[Unit]
Description=...
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
OnCalendar=daily
makes it run every midnight, Persisten=true
on boot if there was at least one missed run.
answered Dec 28 '18 at 6:56
x-yurix-yuri
1,17811642
1,17811642
add a comment |
add a comment |
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%2f48203%2frun-script-once-a-day-with-systemd%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
3
I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days?
– Krzysztof Adamski
Sep 14 '12 at 18:29
Exactly. I will make a backup every day no matter how often I reboot my PC.
– Fu86
Sep 14 '12 at 22:42
5
If you're not hung up on systemd, this is exactly what anacron is for.
– Gilles
Sep 14 '12 at 23:48
I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete.
– Krzysztof Adamski
Sep 15 '12 at 9:16
That's right. That's why I'm currently using anacron and the good old at, with a daily job like
echo "obnam backup" | at "now + 10 minutes"
– Adrien Clerc
Sep 14 '13 at 10:33