8

What would be the simplest way to launch a script during the boot or desktop startup process in debian?

The script in question consists of a single command (ifup wlan0) to connect the wifi and requires root privileges. My system is debian testing, slim login manager, and jwm as window manager.

I have tried the following:

  1. creating the .service way with systemd. It starts the script, but turns it off at desktop login, can't figure out why.
  2. using the startup command in Jwm, but it fails I assume because launching ifup requires root privileges.
  3. put the command in the .bashrc file. same as the above
  4. place the script in the /etc/rc5.d directory.

nothing worked so far. suggestions?

1
  • 3
    Have you considered just using a standard method such as network manager (which does have CLI support). Commented Oct 8, 2018 at 6:37

2 Answers 2

11

In case anyone else needs to know, this is what eventually worked.

  1. create a /etc/rc.local file
  2. chmod it 755
  3. in the rc.local file I put:

Code:

#!/bin/sh -e
# This script is executed at the end of each multiuser runlevel

/path/to/my/script  

exit 0
4
  • 1
    NOTE: systemd will create a rc.local.service as a wrapper and run it at boot. Commented Oct 9, 2018 at 17:40
  • 1
    Don't forget to make rc.local executable! Commented Jul 21, 2019 at 2:33
  • @skryvets chmod 755 makes it executable for all Commented Aug 29, 2019 at 8:46
  • 3
    The network is not ready when this file is executed. Commented Sep 18, 2020 at 10:00
4

This works for me:

cat > /etc/init.d/my-start-script <<EOL
#! /bin/bash
### BEGIN INIT INFO
# Provides:       my-start-script
# Required-Start:    \$local_fs \$syslog
# Required-Stop:     \$local_fs \$syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts my-start-script
# Description:       starts my-start-script using start-stop-daemon
### END INIT INFO

# put your script here

exit 0
EOL
chmod 755 /etc/init.d/my-start-script
update-rc.d my-start-script defaults

Your script should run after every reboot. The comments after /bin/bash are required for update-rc.d

3
  • This seems to be the right answer, however update-rc.d requires using sudo or similar. Commented Sep 28, 2021 at 20:32
  • doesnt work for me , atleast in debian 12 Commented May 15, 2024 at 16:47
  • Works for me in Debian 12 :) The header (### BEGIN INIT INFO ...) is obligatory Commented May 18 at 20:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.