6

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?

RalfFriedl
  • 8,816
  • 6
  • 23
  • 34
black-clover
  • 321
  • 1
  • 2
  • 7
  • 3
    Have you considered just using a standard method such as network manager (which does have CLI support). – jordanm Oct 08 '18 at 06:37

2 Answers2

9

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
Mathieu
  • 2,679
  • 1
  • 20
  • 25
black-clover
  • 321
  • 1
  • 2
  • 7
3

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

user896993
  • 131
  • 1