0

I need to run the command sudo vulkaninfo each time the system starts up (I know how to do it when system wakes up from sleep, i.e. in /usr/lib/pm-utils/sleep.d/somescript). This command should be global, so all users will run this command at startup. I tried adding a script to profile.d under /etc/profile.d, but that resulted in me not being able to login. rc.local is only local, so that will not work. What options do I have?

Edit: I need to be able to do this from a terminal, as I am creating a script that automates my system setup, so programs will not work. So for example I need a command that can create the file, append the command and move the file to where system startup files are located.

2
  • please see my edit
    – user967514
    Jun 20, 2019 at 20:38
  • is cron for all users?
    – user967514
    Jun 20, 2019 at 20:55

1 Answer 1

1

I’d use root’s crontab with @reboot for that, it can easily be edited from a root script:

(crontab -l 2>/dev/null; echo "@reboot vulkaninfo") | crontab -

This adds the line @reboot vulkaninfo to root’s crontab, which runs vulkaninfo with root permissions on every boot.

Note that cron has a minimal environment, if your command needs environment variables set either set them manually or source a file which sets them, e.g. $HOME/.profile. The command might also be executed too early in the startup process, a simple sleep command or a testing loop are ways around that.

Further reading:

You must log in to answer this question.