How to run sudo commands on startup and when device is detected

Hi, I have 2 somewhat similar problems. I want to run a command at startup and also when a device is plugged in (a graphics screen tablet), and also to run a command that mounts a harddrive when the computer turns on.

I am not familiar with this sort of thing at all, but I know the commands I want to run, because they work when I type them in manually. These are the 2 commands I want to run at startup:

This is to map the tablet screen’s pen input to itself (otherwise the pen input is mapped across all monitors). I also need this to run when this device is turned on, because if I turn if off and back on the setting resets. It’s a tablet screen that plugs in through HDMI.

xsetwacom --set “Wacom Cintiq 16 Pen stylus” MapToOutput HDMI-A-0

This is to mount the hard drive to the directory I want (~/Kiophen):

sudo mount /dev/nvme0n1p4 ~/Kiophen

I saved them as their own .sh files and made entries for them in the ‘Application Autostart’ tab in the ‘Session and Startup’ program, but they don’t do anything when I turn the computer on. I have googled around and don’t know what to do.

I have also ran sudo chmod -x [script name] on them with no errors but it did not do anything.

Why not simply create an entry in /etc/fstab to mount on system startup? How come you’re relying on a startup script? Using “sudo” in an autostart script cannot prompt you to enter your password.

As for the first script (xsetwacom), you’re saying it also doesn’t run upon startup?

I do not know what /etc/fstab is or how to use that. Also, yes the xsetwacom command does not work.

But you can add a line in the sudoers file (with sudo visudo) to allow a whole program or a specific command to be executed as sudo without password :stuck_out_tongue: .

To be clear I’m not recommending that to OP, especially when I read that:

Here is some reading, time to learn:

//EDIT: for the command when the tablet is plugged, I think this is doable with udev rules but I’m a baby when it comes to that.

The file-system table (fstab) is a simple text file located at /etc/fstab

You can modify it with the nano text editor,

sudo nano /etc/fstab

Then add a single entry for your mount, something like this:


device mountpoint fs-type options dump check


/dev/nvme0n1p4 /home/Kiophen ext4 defaults 0 1

You can exit the nano text editor with CTRL+X and hitting “y” to confirm the changes.

I’m assuming it’s an ext4 file-system?

Double-check the entry. It’s your system after all, and I threw out an example with /dev/nvme0n1p4 for illustrative purposes.

Searching wikis I found that:

Also found that about udev:

Second link for udev is not specific to Arch/Manjaro though, just for general information.

Probably the article on Manjaro wiki would be enough?

Thank you all for the responses, I went and looked into those articles. I got the UUID from the drive using the command on the wiki, then added it to the fstab file using nano, and now it is mounting correctly at startup like I want it to. :smiley: It is an ntfs system so I typed that in instead of ext4.

I got the xsetwacom command to work on startup, I realized that it is in fact working, but if I turn my tablet off then it does not keep that configuration (not a bug). I usually turn my tablet off when I turn on my computer, but I noticed now that it does work on startup.

I am looking into udev and it is difficult. I do not understand how to get the device name. The manjaro wiki does not have information for my issue. Manjaro detects my tablet, and xsetwacom is working. I will keep looking into udev.

1 Like

I saw “udevadm” as a command on that wiki page, and I ran “udevadm --help” to see if I could decipher. “udevadm monitor” gave me some information that I tried with some other commands from the wiki page. I read over the wiki article and eventually got some understanding. I made a .rules file in /etc/udev/rules.d and added some information from the device, like the idVendor, idProduct, and other fields that are in the example in the wiki page for udev, along with a RUN+="~/script" at the end of the file to try and run the script when the device is plugged in. It didn’t do anything, so I just made the file:

KERNEL=="*", RUN+="~/script"

and saved that in the rules.d folder as tablet.rules. I made the script chmod -x. This does not do anything, the KERNEL=="*" part from my understanding should run the script whenever anything happens with udev, but I turned on/off my tablet and it did nothing. I put in a line in the file to write a line to a file if it’s ran, and the log is empty, so I know it is just not being run at all instead of something else happening.

I could not get udev to execute a script when the tablet was plugged in, after learning udev as well as a solution I saw about using “systemd” alongside udev, but nothing worked. I made a keyboard shortcut in xfce settings instead.

Sometimes, simple workarounds work too :stuck_out_tongue:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.