I would like to run a command (that turns off bluetooth devices) at every startup. I normally use cron for these, but this is a command that needs to be ran as root. How do I do this?
4 Answers
You can still use cron to do it.
make an entry in /etc/crontab like this
@reboot root /path/to/your/command
or as root type
crontab -e
and make an etry like:
@reboot /path/to/your/command
The /etc/crontab is the global crontab and thus you need to specify the user, crontab -e invokes the per-user crontab.
As you are already using cron, you can use @reboot
as the time specification for a cron entry. On Debian/Ubuntu, the entry could be in a file in the /etc/cron.d
directory.
I use the blueman tools to configure Bluetooth services. Configuration should be sticky.
If you want to completely disable Bluetooth, you should consider using systemctl
to disable
and stop
the Bluetooth and blueman-mechanism services. Disabling will prevent starting the services on reboot, and stopping will kill any currently running services.
Original/Obsolete: You could try putting the commands in /etc/rc.local
. Commands in this file should be run at the end of the boot sequence.
Disabling the drivers, and or software as has been described by @skrewler is often a good solution.
-
Using
/etc/rc.local
is outdated (Source: linuxhint.com/use-etc-rc-local-boot). Jul 27, 2022 at 8:31
You're looking to modify your init.d
scripts / setting. This can get complex and depends on your distro. You might be able to edit or create /etc/init/bluetooth.conf
or /etc/defaults/bluetooth
. But I think Vixie Cron supports cron jobs for root and has a start up time setting.