当我关闭我的电脑时,我正在运行一个脚本。我正在运行 ubuntu 14.04,并且在“/etc/init.d/”中有我的脚本“save_log.sh”。该脚本具有执行权限(sudo chmod +x /etc/init.d/save_log.sh)。我还在“/etc/rc0.d/”中创建了一个目标为“/etc/init.d/save_log”的链接。
我已经测试过这个脚本在关闭我的笔记本电脑时正在运行(一块但正在运行)。
我正在尝试保存日志文件并上传到 S3(亚马逊网络服务)。对于这个任务,我正在制作一个“tar.gz”,其中包含具有特定文件名的所有日志文件。此文件名取决于服务器(或笔记本电脑)的 IP。
当我在我的控制台中运行此脚本时,它会成功运行,并且该文件是使用包含 IP(我的笔记本电脑)的文件名创建的,并且该文件已上传到 S3。当我关闭我的笔记本电脑时,文件被创建但名称没有 IP 并且文件没有上传。
我为此脚本创建了一个日志,并为 ifconfig 命令添加了输出:
ifconfig: lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packet:6432 errors:0 drop:0 overruns :0 帧:0 TX 数据包:6432 错误:0 丢弃:0 超限:0 载波:0 冲突:0 txqueuelen:0 RX 字节:1159509 (1.1 MB) TX 字节:1159509 (1.1 MB)
此输出没有网络 IP。在runlevel0中,网络是否被禁用?可以激活吗?有什么想法可以解决这个问题吗?
更新
我的 /etc/rc0.d/ (ubuntu 14.04) 中的内容:
eltortuganegra@eltortuganegra:~$ ll /etc/rc0.d/
total 20
drwxr-xr-x 2 root root 4096 jun 11 16:31 ./
drwxr-xr-x 152 root root 12288 jun 12 09:07 ../
lrwxrwxrwx 1 root root 24 jun 11 13:29 K01save_logs -> /etc/init.d/save_logs.sh*
lrwxrwxrwx 1 root root 17 jun 9 10:27 K09apache2 -> ../init.d/apache2*
lrwxrwxrwx 1 root root 29 jun 9 10:14 K10unattended-upgrades -> ../init.d/unattended-upgrades*
lrwxrwxrwx 1 root root 20 jun 9 10:14 K20kerneloops -> ../init.d/kerneloops*
lrwxrwxrwx 1 root root 19 jun 9 11:35 K20memcached -> ../init.d/memcached*
lrwxrwxrwx 1 root root 15 jun 9 10:14 K20rsync -> ../init.d/rsync*
lrwxrwxrwx 1 root root 27 jun 9 10:14 K20speech-dispatcher -> ../init.d/speech-dispatcher*
lrwxrwxrwx 1 root root 22 jun 11 11:07 K21spamassassin -> ../init.d/spamassassin*
-rw-r--r-- 1 root root 353 mar 13 02:33 README
lrwxrwxrwx 1 root root 18 jun 9 10:14 S20sendsigs -> ../init.d/sendsigs*
lrwxrwxrwx 1 root root 17 jun 9 10:14 S30urandom -> ../init.d/urandom*
lrwxrwxrwx 1 root root 22 jun 9 10:14 S31umountnfs.sh -> ../init.d/umountnfs.sh*
lrwxrwxrwx 1 root root 18 jun 9 10:14 S40umountfs -> ../init.d/umountfs*
lrwxrwxrwx 1 root root 20 jun 9 10:14 S60umountroot -> ../init.d/umountroot*
lrwxrwxrwx 1 root root 14 jun 9 10:14 S90halt -> ../init.d/halt*
我在 Debian 发行版中修改了 rc0.d 目录,我发现:
K06networking -> ../init.d/networking
我想这是为停止网络执行的链接,但在我的 Ubuntu 中,此链接不存在。我想如果我用 K07 下的数字重命名我的链接,那么网络将被启用,我的脚本“save_logs.sh”将正常运行。
我如何知道网络何时被禁用或如何在网络被禁用之前执行我的脚本?