Running a script with systemd on shutdown or reboot
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've made a script which just empties a folder from its contents and then shutdown the pc.
I was wondering if there is a simpler way of doing that automatically when I shutdown or reboot the pc instead of calling the script from the command line. While searching, I found that I probably want a systemd service, but I don't know how to write one and I couldn't find any tutorials on the internet.
After all I just want to run simple single command
rm -rf /my/folder/*
Am I looking the right way, or is there a simpler way to accomplish this?
I want the folder to empty before shutdown and not after the next boot.
systemd shutdown reboot
add a comment |
I've made a script which just empties a folder from its contents and then shutdown the pc.
I was wondering if there is a simpler way of doing that automatically when I shutdown or reboot the pc instead of calling the script from the command line. While searching, I found that I probably want a systemd service, but I don't know how to write one and I couldn't find any tutorials on the internet.
After all I just want to run simple single command
rm -rf /my/folder/*
Am I looking the right way, or is there a simpler way to accomplish this?
I want the folder to empty before shutdown and not after the next boot.
systemd shutdown reboot
add a comment |
I've made a script which just empties a folder from its contents and then shutdown the pc.
I was wondering if there is a simpler way of doing that automatically when I shutdown or reboot the pc instead of calling the script from the command line. While searching, I found that I probably want a systemd service, but I don't know how to write one and I couldn't find any tutorials on the internet.
After all I just want to run simple single command
rm -rf /my/folder/*
Am I looking the right way, or is there a simpler way to accomplish this?
I want the folder to empty before shutdown and not after the next boot.
systemd shutdown reboot
I've made a script which just empties a folder from its contents and then shutdown the pc.
I was wondering if there is a simpler way of doing that automatically when I shutdown or reboot the pc instead of calling the script from the command line. While searching, I found that I probably want a systemd service, but I don't know how to write one and I couldn't find any tutorials on the internet.
After all I just want to run simple single command
rm -rf /my/folder/*
Am I looking the right way, or is there a simpler way to accomplish this?
I want the folder to empty before shutdown and not after the next boot.
systemd shutdown reboot
systemd shutdown reboot
edited Mar 18 at 2:06
Rui F Ribeiro
42.1k1484142
42.1k1484142
asked Jun 2 '17 at 17:13
odorfodorf
112
112
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
This sounds like you are manually creating and managing a temporary directory. If that's the case, check the systemd docs for how it can help with this. See man tmpfiles.d
for details.
add a comment |
Set up a cron
table entry with a schedule of @reboot
to remove and/or recreate the directories in question.
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
It runs at system startup, since shutdown kills thecron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."
– DopeGhoti
Jun 2 '17 at 20:16
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
add a comment |
On Centos/RHEL 7 there still is a /etc/rc.d/rc.local
which uses systemd. I suspect that the same is true on other Linux distributions. This will run the rc.local
scripting at reboot. There is significant commenting and warnings in the file that you should really use the systemd type of run structure.
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%2f368847%2frunning-a-script-with-systemd-on-shutdown-or-reboot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This sounds like you are manually creating and managing a temporary directory. If that's the case, check the systemd docs for how it can help with this. See man tmpfiles.d
for details.
add a comment |
This sounds like you are manually creating and managing a temporary directory. If that's the case, check the systemd docs for how it can help with this. See man tmpfiles.d
for details.
add a comment |
This sounds like you are manually creating and managing a temporary directory. If that's the case, check the systemd docs for how it can help with this. See man tmpfiles.d
for details.
This sounds like you are manually creating and managing a temporary directory. If that's the case, check the systemd docs for how it can help with this. See man tmpfiles.d
for details.
answered Jun 2 '17 at 17:26
Mark StosbergMark Stosberg
4,0681226
4,0681226
add a comment |
add a comment |
Set up a cron
table entry with a schedule of @reboot
to remove and/or recreate the directories in question.
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
It runs at system startup, since shutdown kills thecron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."
– DopeGhoti
Jun 2 '17 at 20:16
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
add a comment |
Set up a cron
table entry with a schedule of @reboot
to remove and/or recreate the directories in question.
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
It runs at system startup, since shutdown kills thecron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."
– DopeGhoti
Jun 2 '17 at 20:16
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
add a comment |
Set up a cron
table entry with a schedule of @reboot
to remove and/or recreate the directories in question.
Set up a cron
table entry with a schedule of @reboot
to remove and/or recreate the directories in question.
answered Jun 2 '17 at 17:39
DopeGhotiDopeGhoti
47.1k56191
47.1k56191
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
It runs at system startup, since shutdown kills thecron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."
– DopeGhoti
Jun 2 '17 at 20:16
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
add a comment |
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
It runs at system startup, since shutdown kills thecron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."
– DopeGhoti
Jun 2 '17 at 20:16
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
does @reboot run the script before shutdown or during the next boot?
– odorf
Jun 2 '17 at 19:35
It runs at system startup, since shutdown kills the
cron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."– DopeGhoti
Jun 2 '17 at 20:16
It runs at system startup, since shutdown kills the
cron
daemon, it cannot tell the kernel "okey dokey, let me just start one new job.."– DopeGhoti
Jun 2 '17 at 20:16
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
i updated my question. thank you for your answer.
– odorf
Jun 2 '17 at 20:38
add a comment |
On Centos/RHEL 7 there still is a /etc/rc.d/rc.local
which uses systemd. I suspect that the same is true on other Linux distributions. This will run the rc.local
scripting at reboot. There is significant commenting and warnings in the file that you should really use the systemd type of run structure.
add a comment |
On Centos/RHEL 7 there still is a /etc/rc.d/rc.local
which uses systemd. I suspect that the same is true on other Linux distributions. This will run the rc.local
scripting at reboot. There is significant commenting and warnings in the file that you should really use the systemd type of run structure.
add a comment |
On Centos/RHEL 7 there still is a /etc/rc.d/rc.local
which uses systemd. I suspect that the same is true on other Linux distributions. This will run the rc.local
scripting at reboot. There is significant commenting and warnings in the file that you should really use the systemd type of run structure.
On Centos/RHEL 7 there still is a /etc/rc.d/rc.local
which uses systemd. I suspect that the same is true on other Linux distributions. This will run the rc.local
scripting at reboot. There is significant commenting and warnings in the file that you should really use the systemd type of run structure.
answered Jun 2 '17 at 23:22
mdpcmdpc
5,11121838
5,11121838
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.
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%2f368847%2frunning-a-script-with-systemd-on-shutdown-or-reboot%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