Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using evrouter to simulate keypresses from my mouses extra buttons. It works great but I need to run the command with sudo to make it work so I can't just use my DE to handle autostart.

I considered init.d but from what I've heard this only works for different stages of boot, and I need this to run as root after login.

$ cat .evrouterrc 
"Logitech G500" "/dev/input/event4" any key/277 "XKey/0"
"Logitech G500" "/dev/input/event4" any key/280 "XKey/9"
"Logitech G500" "/dev/input/event4" any key/281 "XKey/8"
$ sudo evrouter /dev/input/event4

Edit: Alrighty, it looks like I can use lightdm.conf's session-setup-script option to run a script as root. The script I have is below, but as expected when run as root the id -u no longer equals 1000 and the if statement never executes. Is there an argument or variable I can use to get the user name or id?

share|improve this question

2 Answers 2

After your computer boots, Linux runs whatever is in your system's crontab file. Cron is a program that scheduls commands, programs or scripts to run at very specific times of day. Each user has a crontab, but in this situation the system's crontab is appropriate for such a job.

You can configure cron to execute commands or programs when the system boots. So, I think this is what you mean.

In order to edit it accordingly you will want to open your system's crontab file by running the command sudo vim /etc/crontab Feel free to replace ``vim" with your favorite cli text editor.

Add the line (replacing appropriate things with exactly what you need, like commands, ect.) below all the others @reboot evrouter Note: The best idea might be to create a script and place the commands in that and run the script using crontab. It's really your choice.

Depending on your distro, you may or may not have to put who you want the command to be run as after @reboot Most of the time the crontab file will have some comments on the top of the file to instruct you. Of course looking at the other entries in this file will probably be the most useful to you.

share|improve this answer
    
Except I don't need it on boot I need it on login or the system won't have access to the config file containing the keybinds. –  J V Nov 3 '12 at 17:21
    
opening the crontab with a texteditor is a stupid way of editing the crontab. instead use crontab -e. this ensures there are no syntax errors in the corntab when closing the editor. –  l1zard Nov 3 '12 at 17:22

By using lightdm.conf's session-setup-script value I was able to run the command as root as expected.

session-setup-script=/opt/hacks/lightdm-startup

Meanwhile, in another folder:

#!/bin/bash
if [ "$USER" = "j" ]
then
evrouter /dev/input/event4
fi

I'm still not sure why == didn't work in the if statement and = did... Bash is erratic at times.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.