LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Run a script on shutdown before network goes off (https://www.linuxquestions.org/questions/linux-desktop-74/run-a-script-on-shutdown-before-network-goes-off-4175567832/)

sunweb 01-25-2016 03:23 AM

Run a script on shutdown before network goes off
 
Hi. Using K/X/Ubuntu 14.04, but it doesn't really matter as it should be the same in Debian as well.
It doesn't matter how simple script is, it can be:
echo "put it" > /media/network/there
echo "put it" > /home/user/there

If i will put it a link to script to /etc/rc0.d with K04script name it will create file only on local machine, even if i put it in rc3.d and rc5.d with S04script it still doesn't work.

Can someone help me?

jefro 01-25-2016 05:03 PM

Maybe symbolic link? http://unix.stackexchange.com/questi...down-in-debain

sunweb 01-26-2016 02:29 AM

Thats exactly what i did. The script runs but not before network goes down or network disks are unmount.

sunweb 01-26-2016 04:00 AM

Ok, i've found a solution. Though i believe there should be a better way to do it as creating services just for that sounds strange.
Workaround using Upstart(i guess i'd have to write units if systemd will be used for this case as well).

create a file /etc/init/your_name.conf

if you want bash autocompletion to work put a link to /etc/init.d without ".conf" (/etc/init.d/your_name). Though i didn't try with it maybe it'll work too. In my case not needed anyway but if you'll write a script directly in *.conf and want to test it maybe useful.

Put quoted inside of /etc/init/your_name.conf
Quote:

# The deconfiguring-networking bit stops the network from going down until we are done here.

description "Script on shutdown"

start on runlevel [016] or deconfiguring-networking

#exec sh /path/to/script

# or

script

<script body here>

end script
found a solution here -> http://unix.stackexchange.com/questi...eds-network-on


All times are GMT -5. The time now is 08:20 PM.