WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: What scripts are run by/after typing "poweroff"?  (Read 9326 times)

Offline mattrix

  • Newbie
  • *
  • Posts: 14
What scripts are run by/after typing "poweroff"?
« on: March 27, 2011, 11:59:55 PM »
The title says it,
I want to automate some things after poweroff or reboot is typed,
thanks
« Last Edit: March 28, 2011, 08:37:16 AM by mattrix »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11704
Re: What scripts are run by/after typing "poweroff"?
« Reply #1 on: March 28, 2011, 02:05:47 AM »
Hi mattrix
Check out the /opt directory, there are 3  .sh  files for what you want to do.

Offline mattrix

  • Newbie
  • *
  • Posts: 14
Re: What scripts are run by/after typing "poweroff"?
« Reply #2 on: March 28, 2011, 02:42:12 AM »
Hey Rich
I looked at shutdown.sh but it doesn't seem to be called.
The others are for startup.

A stoplocal.sh would be nice.
« Last Edit: March 28, 2011, 02:44:14 AM by mattrix »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: What scripts are run by/after typing "poweroff"?
« Reply #3 on: March 28, 2011, 02:56:47 AM »
Hey Rich
I looked at shutdown.sh but it doesn't seem to be called.
The others are for startup.

A stoplocal.sh would be nice.

poweroff is a built-in unix command, it does not start scripts. shutdown.sh is used by TC's own exit utility.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline mattrix

  • Newbie
  • *
  • Posts: 14
Re: What scripts are run by/after typing "poweroff"?
« Reply #4 on: March 28, 2011, 03:20:19 AM »
so, can I call a script from rc.shutdown then?
« Last Edit: March 28, 2011, 03:23:11 AM by mattrix »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11704
Re: What scripts are run by/after typing "poweroff"?
« Reply #5 on: March 28, 2011, 03:32:49 AM »
Hi mattrix
Until someone posts the correct way , try calling your script near the beginning of rc.shutdown.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: What scripts are run by/after typing "poweroff"?
« Reply #6 on: March 28, 2011, 03:55:58 AM »
Code: [Select]
cat `which exitcheck.sh`
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline mattrix

  • Newbie
  • *
  • Posts: 14
Re: What scripts are run by/after typing "poweroff"?
« Reply #7 on: March 28, 2011, 05:10:38 AM »
Quote
Until someone posts the correct way

I gotta stop looking for the correct way, and think laterally.

Hows this sound?
Poweroff is in busybox,  I just have to link poweroff to my script and call busybox directly from the script.

matt
Now to learn bash scripting, google IS sometimes my friend.
« Last Edit: March 28, 2011, 05:19:37 AM by mattrix »

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: What scripts are run by/after typing "poweroff"?
« Reply #8 on: March 28, 2011, 05:34:02 AM »
IMHO sounds
1. like a dirty hack
2. like reinventing the wheel - when a proper mechanism is provided by the system already
However, that does not mean it could not potentially do the job for a particular system.

Note: bash is not included in base, sh scripting might be preferable where it can be sufficient.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline hiro

  • Hero Member
  • *****
  • Posts: 1229
Re: What scripts are run by/after typing "poweroff"?
« Reply #9 on: March 28, 2011, 07:38:24 AM »
So simple. Create two scripts which do what you want, then run poweroff/reboot at the end of it.
You can name these scripts creatively, I would prefer them to be short for my own use.

Offline cosmin_ap

  • Newbie
  • *
  • Posts: 48
Re: What scripts are run by/after typing "poweroff"?
« Reply #10 on: May 11, 2011, 06:39:10 PM »
2. like reinventing the wheel - when a proper mechanism is provided by the system already

What is the mechanism provided by the system? The only option I see is replacing rc.shutdown with my own script which calls the original rc.shutdown after doing its thing. I'd rather like rc.shutdown have a line somewhere at the top like

[ -x /opt/shutdown.sh ] /opt/shutdown.sh

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: What scripts are run by/after typing "poweroff"?
« Reply #11 on: May 11, 2011, 07:17:27 PM »
What is the mechanism provided by the system?

The /etc/inittab file is the mechanism provided by the system:

::restart:/etc/init.d/rc.shutdown
::restart:/sbin/init
::shutdown:/etc/init.d/rc.shutdown

Simply add your script:

::restart:/usr/local/sbin/myrestart
::restart:/etc/init.d/rc.shutdown
::restart:/sbin/init
::shutdown:/usr/local/sbin/myshutdown
::shutdown:/etc/init.d/rc.shutdown


Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: What scripts are run by/after typing "poweroff"?
« Reply #12 on: May 11, 2011, 11:03:10 PM »
2. like reinventing the wheel - when a proper mechanism is provided by the system already

What is the mechanism provided by the system?

See Reply #3 & Reply #6
« Last Edit: May 12, 2011, 01:12:00 AM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)