I need to run a script before shutting down or rebooting my VPS running Debian 8,to keep count of network statistics.I tried adding the script directly to
/etc/init.d and symlinking it in
/etc/rc6.d, and adding to it the LSB header, making it like an actual service with start and stop and generating the symlinks with update-rc.d, but nothing has worked, it seems like the script isn't executed at all.Maybe it could have to do with it being an VPS, so it doesn't get recognised by the system when it is apparently shut down or rebooted.
I just need a simple mechanism,without having to create a proper service. Also I'd like to know which could be the better way to check if the script is actually being executed or not,some simple way of logging. The script is just this:
RESULT=$(bc <<< "scale =2;($(cat /sys/class/net/venet0/statistics/rx_bytes)/1024/1024/1024)+($(cat /sys/class/net/venet0/statistics/tx_bytes)/1024/1024/1024)+($(cat /root/bw))") echo $RESULT > /root/bw