GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Can I run a command at shutdown?

Mon Nov 12, 2012 8:39 pm

This is a bit of a Linux noob question I guess.

I am running an espeak command when my PI starts up, by adding a command into /etc/rc.local

I was wondering if there is an equivalent script that runs when the PI is shutting down, so I can add an espeak command to say "goodbye" or something similar?

Anybody know?

Thanks

G

User avatar
Arjan
Posts: 262
Joined: Sat Sep 08, 2012 1:59 pm

Re: Can I run a command at shutdown?

Mon Nov 12, 2012 9:03 pm

Hi,

This link http://www.techrepublic.com/article/cus ... w=fullonce might help you.

Arjan.
http://www.raspberrypi-dmx.org/
Open Source DMX/RDM/MIDI/OSC/Art-Net/sACN solutions

GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Re: Can I run a command at shutdown?

Tue Nov 13, 2012 8:15 am

Thanks Arjan, I have read something like this before, but I don't really understand how it helps me.

What I want is a shell script that will run at the very beginning of a $shutdown -h now command.

I apreciate from the run levels that it has to run early before the speech engine and ALSA drivers etc get unloaded, but I don't have a process running that will get stopped and fire a shell script.

This seems like a very basic request to me, isn't there a shell script that gets run by a shutdown command anywhere?

Thanks

G

User avatar
RaTTuS
Posts: 10459
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Can I run a command at shutdown?

Tue Nov 13, 2012 9:14 am

look at athe scripts in
/etc/init.d/
they are what are run as link from the
/etc/rc?.d
directories
S meaning on start up
K meaning Kill
number is when to do it in the list
then the script name
/etc/rc0.d
is what is done on shutdown

there is a command to put the correct links in but it's name escapes me ATM. [you can jut make the llink yourself]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Re: Can I run a command at shutdown?

Tue Nov 13, 2012 8:16 pm

Thanks for the pointers.

I am not sure I fully understand yet, but certainly a step closer now.

G

Introspector
Posts: 1
Joined: Wed Nov 14, 2012 7:06 am

Re: Can I run a command at shutdown?

Wed Nov 14, 2012 7:13 am

The command name should be "chkconfig".
Check the documentation on the web.
Shouldn't be difficult.

GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Re: Can I run a command at shutdown?

Thu Nov 15, 2012 3:28 pm

OK, "chkconfig" isn't quite correct for debian by the looks of things, but I this led me in what I think is the right direction.

Still not working, but here is what I have tried...

I created a file called "shutdown_job" and copied it into the /etc/init.d directory. The files contents are:

#!/bin/sh -e
#
# shutdown_job
#
# Required-Start:
# Required-Stop: sendsigs
# Default-Start:
# Default-Stop: 0 6
# Short-Description: bla
# Description:
### END INIT INFO

do_stop () {
sudo espeak "Goodbye." 2>/dev/null
echo "Goodbye"
}

case "$1" in
start)
# No-op
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
do_stop
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac

:


To give it permissions, I then ran :
sudo chmod 777 /etc/init.d/shutdown_job

I then ran the following command to make it active:
sudo update-rc.d shutdown_job start 1 0 6

I then reboot and at the end of the startup process I get:

[FAIL] startpar: service(s) returned failure: shutdown_job ... failed!

and it doesn't work...

I have checked the /etc/rc0.d and /etc/rc6.d directories and they both contain my K01shutdown_job now.

I am guessing that there is something wrong with the contents of my shutdown_job file. Any ideas where I have gone wrong?

Thanks

G

W. H. Heydt
Posts: 10890
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Can I run a command at shutdown?

Thu Nov 15, 2012 10:34 pm

Make sure you aren't running your "Goodby" process after any service it needs has been killed.

User avatar
RaTTuS
Posts: 10459
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Can I run a command at shutdown?

Fri Nov 16, 2012 7:38 am

you probably need the full path to espeak
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Re: Can I run a command at shutdown?

Fri Nov 16, 2012 8:19 am

Just wanted to say thanks for everyone's help with this so far. This is only a trivial thing, but with your help I am learning more and more about this every day. :)

I don't think it is an issue with the path to espeak because I have a very similar line in my /etc/rc.local script which runs fine.

As for it being run too late, I guess that is a possibility, because the Alsa stuff is also running at K01 and looks like it goes down pretty quickly on a shutdown or reboot. I am not sure how I can promote my script to run before that, as I think K01 is the highest. Is there anyway to make my K01 run before the Alsa K01 script?

Also, I added an echo command before the espeak command just to see if the script was being run, but I still don't see anything.

Any more ideas welcomed...

Thanks

G

User avatar
RaTTuS
Posts: 10459
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Can I run a command at shutdown?

Fri Nov 16, 2012 9:04 am

make it k00
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “Beginners”