You are not logged in.

#1 2008-10-19 04:00:17

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

[SOLVED] Running script on shutdown? (5 Questions!)

What I would like to do is run a script (ArchBoxBaksScript.sh) on shutdown (not needed on reboot).  The first solution I found was to place the script in /etc/init.d, then put a symlink in /etc/rc0.d pointing to the script to run it at run level 0.  Well after not being able to find /etc/init.d I did a little digging and discovered that Arch uses a BSD style init framework, which is, more or less, totally different.

So, my questions are:

1.  Where do I place my script to be run at shutdown?  Do I place it in /etc/rc.d? 

The basic ideas behind BSD rc.d are fine modularity and code reuse. Fine modularity means that each basic "service" such as a system daemon or primitive startup task gets its own sh(1) script able to start the service, stop it, reload it, check its status.

2.  Then what?  I am guessing that I need to add something to /etc/rc.shutdown to get it to run.  Or do I add something to /etc/rc.local.shutdown?  What is the difference between the two?

The difference between rc.shutdown and rc.local.shutdown is that you should only edit rc.local.shutdown; the other one is the script that arch actually uses to shut off.

3.  What is the "something" that I need to add?

su casey -c /etc/rc.d/ArchBoxBaksScript.sh

4.  At the risk of confusing the issue, IF I did want to run it on reboot what would I need to do?

Currently it is working on both shutdown and reboot.  Still not sure how to do just shutdown.

5.  And finally, how is all this "easier" than just copying it into a directory and then adding a symlink or two?

This is still a gawddammed good question that no one has tackled yet!

I know those are a bunch of questions to ask in one post, but I thought I'd get my money's worth big_smile .

Thanks in advance,
Monstermudder78

Last edited by monstermudder78 (2008-10-19 06:00:17)

Offline

#2 2008-10-19 04:08:50

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] Running script on shutdown? (5 Questions!)

Your issue is complicated by you not needing to run it on rebooting. Normally you would just add the command to /etc/rc.local.shutdown (it doesn't matter where the script is). The difference between rc.shutdown and rc.local.shutdown is that you should only edit rc.local.shutdown; the other one is the script that arch actually uses to shut off.

I don't know how you would get your script to run only when not rebooting, sorry.

Last edited by fflarex (2008-10-19 04:09:08)

Offline

#3 2008-10-19 04:10:36

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: [SOLVED] Running script on shutdown? (5 Questions!)

fflarex wrote:

Your issue is complicated by you not needing to run it on rebooting. Normally you would just add the command to /etc/rc.local.shutdown (it doesn't matter where the script is). The difference between rc.shutdown and rc.local.shutdown is that you should only edit rc.local.shutdown; the other one is the script that arch actually uses to shut off.

I don't know how you would get your script to run only when not rebooting, sorry.

Well, it's not that the script CAN'T run at reboot, it's just that I don't need it to.

Offline

#4 2008-10-19 04:13:14

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] Running script on shutdown? (5 Questions!)

Ok, well you can use my suggestion then. Was I clear enough or should I elaborate a little?

Offline

#5 2008-10-19 04:16:51

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: [SOLVED] Running script on shutdown? (5 Questions!)

fflarex wrote:

Ok, well you can use my suggestion then. Was I clear enough or should I elaborate a little?

I think I am figuring it out.  I will report back in just a bit to hopefully mark this baby [SOLVED], thanks!

Offline

#6 2008-10-19 04:45:27

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: [SOLVED] Running script on shutdown? (5 Questions!)

Ok, I'm back and I can't quite figure it out.  Here is what I have done so far:

1.  Added ArchBoxBaksScript.sh to /etc/rc.d .  Here it is (and please disregard the now irrelevant notes at the top), I have tested each command separately and they seem to work individually.

#!/bin/bash 


#Place in /etc/init.d
#Place Symlinks in /etc/rc0.d for Shutdown
#   sudo ln -s /etc/init.d/rensa.sh /etc/rc0.d/K10rensa.sh
#and /etc/rc6.d for Reboot
#   sudo ln -s /etc/init.d/rensa.sh /etc/rc6.d/K10rensa.sh #!/bin/bash 


#Archive and compress files
tar -czf /home/casey/ArchBoxBak.tar.gz /home/casey/.bashrc /home/casey/.conkyrc /home/casey/.xinitrc /home/casey/scripts /home/casey/.keytouch2 /home/casey/.config

#Copy to Server
scp /home/casey/ArchBoxBak.tar.gz casey@192.168.1.200:/home/casey

#Clean up
rm /home/casey/ArchBoxBak.tar.gz

2.  I added to /etc/rc.local.shutdown and it now looks like this:

#!/bin/bash
#
# /etc/rc.local.shutdown: Local shutdown script.
#
#Run script to backup configs to server
/etc/rc.d/ArchBoxBakScript.sh

Results:
The tar file is not copied to the server.  If I comment out the cleanup portion the file is still on my local machine when I restart.  If the cleanup portion is allowed to run the tar file is missing, indicating the script runs to completion.  The problem seems to be with the scp line, but it works when I run it by itself from terminal.  I'm not sure what to check next.

Offline

#7 2008-10-19 05:03:14

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] Running script on shutdown? (5 Questions!)

Sorry, I've looked over your script and /etc/rc.local.shutdown, but I don't see anything wrong with it. It seems a little odd to me that you would place the script in /etc/rc.d/, but I can't think of any reason why that would affect the functionality. I don't use scp, but if it works from the terminal it should work here too. Someone else will have to help you from here on out.

Offline

#8 2008-10-19 05:08:51

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: [SOLVED] Running script on shutdown? (5 Questions!)

fflarex wrote:

Sorry, I've looked over your script and /etc/rc.local.shutdown, but I don't see anything wrong with it. It seems a little odd to me that you would place the script in /etc/rc.d/, but I can't think of any reason why that would affect the functionality. I don't use scp, but if it works from the terminal it should work here too. Someone else will have to help you from here on out.

In your opinion where should I put it?  I just put it in rc.d because that is where the scripts that are run by rc.shutdown live, so I thought it belonged there?  I'm really not sure.

Offline

#9 2008-10-19 05:17:01

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] Running script on shutdown? (5 Questions!)

The only reason it matters where you put it is for organization. You can keep it right where it is if that makes sense to you. I generally think of /etc/rc.d as where all the daemons live, and would probably put the script in ~/bin if it's a personal script, or /usr/local/bin or /usr/local/sbin if it's supposed to be a system-wide script.

Oh, and something that I just thought of: are you testing this script as root when you run it from a terminal? Because that is how it is getting run on shutdown...

Offline

#10 2008-10-19 05:19:36

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: [SOLVED] Running script on shutdown? (5 Questions!)

fflarex wrote:

The only reason it matters where you put it is for organization. You can keep it right where it is if that makes sense to you. I generally think of /etc/rc.d as where all the daemons live, and would probably put the script in ~/bin if it's a personal script, or /usr/local/bin or /usr/local/sbin if it's supposed to be a system-wide script.

Oh, and something that I just thought of: are you testing this script as root when you run it from a terminal? Because that is how it is getting run on shutdown...

AH HA!  THAT'S IT!  I set up the shared keys using my user, when I run it as root it needs a password.  Thanks a million!

Offline

#11 2008-10-19 05:25:29

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] Running script on shutdown? (5 Questions!)

If you don't want your keys under the root account, you could change your line in /etc/rc.local.shutdown to run it as a normal user:

su casey -c /etc/rc.d/ArchBoxBaksScript.sh

Or change the actual script to use su...

Last edited by fflarex (2008-10-19 05:26:30)

Offline

#12 2008-10-19 05:32:17

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: [SOLVED] Running script on shutdown? (5 Questions!)

fflarex wrote:

If you don't want your keys under the root account, you could change your line in /etc/rc.local.shutdown to run it as a normal user:
su casey -c /etc/rc.d/ArchBoxBaksScript.sh
Or change the actual script to use su...

Thanks!  I moved the keys to the root account to check it, and sure enough, it works now.  I am somewhat aware of the security risks of doing so and I may look into some of the alternatives you suggested in the morning.  But hey, thanks again, I've been working on this for a couple of hours now and just couldn't crack it on my own.  I owe you one.

Offline

Board footer

Powered by FluxBB