You are not logged in.

#1 2010-06-23 18:38:28

sharris
Member
Registered: 2010-06-12
Posts: 29

How to run a script automatically just before Reboot or Shutdown

Hello all,

Could someone tell me what folder or what entries to be made if I want an event to take place before the machine actually start the reboot/shutdown process.  For instants, i usually mount my USB flash drive but sometime I forget to umount it, which will cause a dirty file system when restarting the machine.  Would anyone have an example to get me going.  It's just like when rc.conf will do added things for you during start-up if special code/script was inserted.

There are other things I like to do before the machine reboot or shutdown, like, to run a very small scripts to automatically kill a certain process "first", before the rest and before rebooting.  I'm sure I can write the code but I don't know where it goes.

Thanks in advance

PS: Thanks fsckd, Your explanation of SKIP/SEEK for dd has never been explained so well in any documentation, or on ANY web-site I ever been to in 6 months pass.  Now I know how it really works and i'm getting it down to a science.  I did not use it for what my thread indicate because in the end the other suggestions were better, but still I Thank God I finally know how to use SKIP/SEEK in dd.  dd is my most use tool for what I do.

Offline

#2 2010-06-23 18:46:55

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: How to run a script automatically just before Reboot or Shutdown

I think you want /etc/rc.local.shutdown . This runs right before the daemons are stopped.

Offline

#3 2010-06-23 18:49:52

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: How to run a script automatically just before Reboot or Shutdown

umm ... you're welcome, sorry if I was a bit harsh ...

As for your question, see /etc/rc.local and its analogue /etc/rc.local.shutdown .

edit: hello ataraxia

Last edited by fsckd (2010-06-23 18:51:17)


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#4 2010-06-23 18:51:00

milomouse
Member
Registered: 2009-03-24
Posts: 940
Website

Re: How to run a script automatically just before Reboot or Shutdown

I put my stuff in /etc/rc.shutdown as mentioned already. If you want something simple for your shutdown/reboot stuff I'd just use it as a function in your shell rc file. If you're worried about making sure it's unmounted, the script or function could include something like:

reboot() {
if [ -b /dev/disk/by-uuid/XXXXX ]; then
  umount /dev/disk/by-uuid/XXXXX
fi
reboot
}

Same with poweroff or halt, whatever. Just an idea..
(typo)

Last edited by milomouse (2010-06-23 18:54:19)

Offline

#5 2010-06-24 02:12:53

sharris
Member
Registered: 2010-06-12
Posts: 29

Re: How to run a script automatically just before Reboot or Shutdown

Wow! I just added this and it works great ...

cd/     # to move out of the mounted directory if I was in it under another terminal.
Sleep 1 # give it room to think
ls     #  to see changed directory on screen
Sleep 1 # give it room to think
umount /b     # do the main thing
Sleep 1 # give it room to think

There something new every day to learn with this OS.  Just when you get one thing right here's comes another. I guest it took 20 years to build LINUX and I read the kernel has something like 10 - 30 million lines of code or better.  Some how I lost the better link that went much deeper.  30 million lines of code mean billions of documentation to read.  But you still got to find the right one first.  So I guest we read and still have to ask questions just to get to the good parts, and than ...

http://en.wikipedia.org/wiki/Source_lines_of_code

Thanks again

Offline

#6 2010-06-24 08:32:58

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: How to run a script automatically just before Reboot or Shutdown

sharris wrote:

Wow! I just added this and it works great ...

cd/     # to move out of the mounted directory if I was in it under another terminal.
Sleep 1 # give it room to think
ls     #  to see changed directory on screen
Sleep 1 # give it room to think
umount /b     # do the main thing
Sleep 1 # give it room to think

There something new every day to learn with this OS.  Just when you get one thing right here's comes another. I guest it took 20 years to build LINUX and I read the kernel has something like 10 - 30 million lines of code or better.  Some how I lost the better link that went much deeper.  30 million lines of code mean billions of documentation to read.  But you still got to find the right one first.  So I guest we read and still have to ask questions just to get to the good parts, and than ...

http://en.wikipedia.org/wiki/Source_lines_of_code

Thanks again

Arch should already automatically unmount your USB drive. If it isn't unmounted, that's a bug and ought to be filed at http://bugs.archlinux.org

Offline

#7 2018-04-14 03:14:20

SealsRock12
Member
Registered: 2018-04-03
Posts: 83

Re: How to run a script automatically just before Reboot or Shutdown

You can use Cron:
here is the link


-- SealsRock12

Offline

#8 2018-04-14 03:57:50

circleface
Member
Registered: 2012-05-26
Posts: 639

Re: How to run a script automatically just before Reboot or Shutdown

Please do not necrobump old threads, especially ones that aren't even using technology still included by default with arch.  rc.local has been deprecated since systemd came around.

Offline

#9 2018-04-14 06:14:20

seth
Member
Registered: 2012-09-03
Posts: 50,924

Re: How to run a script automatically just before Reboot or Shutdown

And
* cron is not event triggered while
* systemd has hooks in /usr/lib/systemd/system-shutdown/ and
* devices should™ be unmounted automatically anyway by now.

Offline

#10 2018-04-14 09:44:40

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,620

Re: How to run a script automatically just before Reboot or Shutdown

Please pay attention to the dates.

Don't necrobump: https://wiki.archlinux.org/index.php/Co … bumping.22

Closing.

Last edited by V1del (2018-04-14 09:45:31)

Offline

Board footer

Powered by FluxBB