连接到网络后启动脚本

问题描述:

我有一个存储在每天晚上重新启动的工作站上的聊天工具。现在它重新启动并在启动时为机器人运行脚本,而无需任何人登录。通常,它将在那段时间连接到网络,但如果连接网络需要更长时间,脚本将退出错误。连接到网络后启动脚本

我试过将它添加到rc.local文件中,我也尝试在init.d目录中放置一个自定义脚本并运行 update-rc.d script.sh defaults

一旦计算机连接到网络而没有任何人需要登录,我将编辑哪个文件来运行我的脚本?

我试过四处寻找,并看到很多事例,一旦你登录的工作,我也看到this answer,看起来可能是正确的轨道?

--update--

我一直在读入/etc/network/if-up.d/,看看脚本被放置在那里,标记为可执行没有.sh扩展,它应该运行。 Debian的文档herehere解释:

The ifupdown system automatically runs scripts installed in- 
"/etc/network/*/" while exporting environment variables to scripts. 

The ifupdown-extra package provides easy network connection tests for use 
with the ifupdown package. 

    -The network-test(1) command can be used from the shell. 

    -The automatic scripts are run for each ifup command execution. 

The network-test command frees you from the execution of cumbersome low 
level commands to analyze the network problem. 

The automatic scripts are installed in "/etc/network/*/" and perform the following: 

    -Check the network cable connection 

    -Check duplicate use of IP address 

    -Setup system's static routes based on the "/etc/network/routes" definition 

    -Check if network gateway is reachable 

    -Record results in the "/var/log/syslog" file 

这个过程中是否会出现在启动?如果一个脚本放在这里,它只会在没有人需要登录的情况下建立连接时运行吗?如果连接的建立之前我的脚本运行时,它会因不能没有来自主机的响应,将需要手动运行一次有人用武之地。

--update--

脚本不当计算机重新启动并连接到网络上正在执行,我试图寻找到为什么读这个答案here和NetworkManager.conf变化值从

[ifupdown] 
managed=false 

[ifupdown] 
managed=true 

我错过了什么?我知道脚本没有被调用,因为它应该输出到日志中,但日志永远不会出现。

+1

看看'/ etc/network'文件夹... – arkascha

+0

@arkascha我更新了我的问题!感谢您的支持 –

+0

显然,放置在那里的脚本在“启动”时也会被考虑,因为它使用这个系统来提取网络接口。显然,一旦网络接口被拉高,脚本就会被执行。这意味着您可能需要检查脚本_which_界面开始的脚本。你会在现有的脚本中找到这样的例子,'openssh-server'脚本是一个很好的起点。 – arkascha

到现在为止,一切都正确完成。我读this回答并跑

sudo ifup --all -v 

它已经显示我在我的脚本中有语法错误。修复后,它按预期工作。