Arch Linux 启动后一分钟运行脚本

Ger*_*ddc 5 startup arch-linux systemd raspberry-pi netctl

我已经用netctl在eth0和wlan0之间架起了一座桥。如果我告诉它在启动时配置 eth0 和 wlan0,然后让我在它启动后手动启动网桥,它就可以正常工作。如果我告诉网桥也自动启动,但出于某种原因,WLAN 适配器不会连接到接入点。因此,我需要“netctl start bridge”在整个系统完成启动后运行一分钟左右。知道我应该怎么做吗?

附注。这是一个无头系统,因为没有 xorg,所以在 xorg 启动时运行它是行不通的。

anl*_*lar 19

您可以使用 systemd 计时器在启动后一分钟执行脚本。

首先,创建服务文件(/etc/systemd/system/myscript.service):

[Unit]
Description=MyScript

[Service]
Type=simple
ExecStart=/usr/local/bin/myscript
Run Code Online (Sandbox Code Playgroud)

然后创建计时器(/etc/systemd/system/myscript.timer):

[Unit]
Description=Runs myscript one minute after boot

[Timer]
# Time to wait after booting before activation
OnBootSec=1min
Unit=myscript.service

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

现在启用并运行它:

# systemctl enable myscript.timer
# systemctl start myscript.timer
Run Code Online (Sandbox Code Playgroud)


Liv*_*ack 4

Arch 使用 systemd 来管理启动进程(还有守护进程等)。

您可以编写一个脚本来简单地执行您想要的命令,或者休眠一分钟然后执行。然后按照上面的说明将其添加到启动过程中

维基百科

如果添加睡眠:

#!/bin/sh
sleep 60 # one min
netctl start bridge
Run Code Online (Sandbox Code Playgroud)

它应该工作得很好。Systemd 在执行脚本时应该生成另一个进程,这样它就不会导致系统挂起。

  • “systemd”启动脚本中的“sleep”与“systemd”启动脚本的目的相反。 (3认同)