Arch Linux run script a minute after boot
Solution 1
Arch uses systemd to manage startup processes (daemons and the like as well).
You can write a script that simply executes the command that you want, or sleep for a min and then execute. Then add it to the boot process with the instructions on the
if you add a sleep:
#!/bin/sh
sleep 60 # one min
netctl start bridge
It should work perfectly fine. Systemd should spawn another process when it executes your script so it shouldn't make your system hang.
Solution 2
You can use systemd timers to execute script a minute after boot.
First, create service file (/etc/systemd/system/myscript.service):
[Unit]
Description=MyScript
[Service]
Type=simple
ExecStart=/usr/local/bin/myscript
Then create timer (/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
Now enable and run it:
# systemctl enable myscript.timer
# systemctl start myscript.timer
Solution 3
If you want something simple that's non-blocking, add the following to /etc/rc.local:
( sleep 60 && /path/to/command_or_script [opts] ) &
Related videos on Youtube
Gerharddc
Updated on September 18, 2022Comments
-
Gerharddc over 1 year
I have set up a bridge between eth0 and wlan0 with netctl. It works fine if I tell it to configure eth0 and wlan0 at startup and then for me to manually start the bridge after it boots. If I tell the bridge to start automatically as well though for some reason the wlan adapter does not connect to an access point. I therefore need "netctl start bridge" to run a minute or so after the entire system has finished booting. Any idea how I should do this?
PS. This is a headless system as in no xorg so running it at xorg startup won't work.
-
Gerharddc almost 10 yearsWell that's obvious but I have no idea how to make it start at the right time
-
Livinglifeback almost 10 yearsadd a sleep to is #!/bin/sh sleep(60) # one min netctl start bridge It shouldn't cause the system to hang as it should be spawned as a separate process.
-
Gerharddc almost 10 yearsCould you please just give me an example file for this as I'm a bit to unexperienced to know how to implement that.
-
Gerharddc almost 10 yearsOk I've managed to get the file written and am now testing it
-
Gerharddc almost 10 yearsWell this definitely works for getting it to run at the right time but strangely this still does not solve the problem that I am trying to solve with it
-
Livinglifeback almost 10 yearsWhat problem are you trying to solve?
-
Gerharddc almost 10 yearsThe problem with the automatic bridge messing up my wlan connection
-
Livinglifeback almost 10 yearsWhat do you use to connect your wlan? wicd, networking manager etc?
-
Gerharddc almost 10 yearsI use netctl but luckily it seems it just starting working after I increased the delay some more
-
Livinglifeback almost 10 yearsGlad it worked for you.
-
godlygeek almost 10 yearsThe parens in "sleep(60)" are not necessary or syntactically valid for shell scripts.
-
mikeserv almost 10 years
sleep
in asystemd
startup script is contrary to the purpose of having asystemd
startup script. -
StrongBad almost 10 yearsCouldn't you add an after line so the script runs after wlan0 is configured?
-
anlar almost 10 years@StrongBad, probably you can add
Requires=sys-subsystem-net-devices-wlan0.device
andAfter=sys-subsystem-net-devices-wlan0.device
to service to ensure that it will start after wlan0 configuration. But I haven't tested it by myself.