Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm trying to execute a script that does an rsync to another machine (among other things) upon reboot and/or shutdown. I've tried creating a symbolic link to the script in /etc/rc6.d for reboot and /etc/rc0.d for shutdown but the script never executes because the network is already killed. I realize the scripts run in alphabetical order which is why I would do /etc/rc6.d/K01MyScript.sh but that doesn't work either.
I'm running CentOS 6.2 + gnome 3. I believe NetworkManager is what is "handling" the network connection... which gets killed at K32NetworkManager.
Is the runlevel way the right approach or can I try something else?
I realize the scripts run in alphabetical order which is why I would do /etc/rc6.d/K01MyScript.sh but that doesn't work either.
I think it is not the Network Manager that kills but the moment when the protocol and carrier are closed. <I don't run centOS but if it uses /etc/inittab --the way Slackware does-- you might be able to define rc6 action by running your rsync script first before it hands over the signal.>
When entering a new runlevel the start scripts run first i.e. SXX i.e S00xx - S99xx. Your rsync script should be S00MyScript.sh so it is the first script to run.
A S00 script might already exist so you will need to move links around.
You'd think that would work, right? I tried a series of things:
First, that script didn't run as S00aaaa.sh (just so it executes before kill/halt/shutdown, etc.) Then, I decided to test the "network theory" by creating another simple script that just touches a file and surely, the file was there after I rebooted it. So... it appears that the K scripts run before the S scripts... right? Network was not available for it to run an rsync. I tested that theory again by changing the same script that does a ping and writes to a file. Now it writes a file but the contents are empty. What is going on?
Distribution: K/Ubuntu 12.04/14.04, Scientific Linux 6.3/6.4, Android-x86, Pretty much all distros at one point...
Shutdown might not necessarily work with the following, but startup should,... You can use cron/anacron for an rsync job on startup, just make sure to make the cron file reference it... On shutdown you'd likely have to modify your init states,... but you could, again, look into editing it so that it executed a cron job.
That way, startup... no mods,... shutdown,... minimal mods... All the real work would be defined in the cron job.
I've tried creating a symbolic link to the script in /etc/rc6.d for reboot and /etc/rc0.d for shutdown but the script never executes because the network is already killed. I realize the scripts run in alphabetical order which is why I would do /etc/rc6.d/K01MyScript.sh but that doesn't work either.
Try putting your scripts in /etc/rc5.d or /etc/rc3.d or whatever level CentOS normally runs at. I don't use CentOS, but I assume 5 is the standard runlevel.
In my experience, since you don't run at 0 or 6, scripts placed here are not executed. I'm fairly sure that a startup script placed in /etc/rc5.d will execute if you boot up to run level 5. As far as shutting down goes, it may be necessary to use the shutdown command (shutdown -r now) rather than the init command (init 6) to get the kill version to run. Again, I have no CentOS experience, so that's just a potential gotcha to be aware of.
Is running rsync on shutdown a good idea? I'm particularly thinking of an emergency like flooding or imminent power outage. If you really have to shutdown *now*, the last thing you want is an rsync that could take several minutes to run, especially since rsync by its nature will leave buffers unsynced if the power went out in the middle of it.