Run script on login (script with sudo) or startup
1. Using /etc/profile.d
You can run the script on login by placing the script in /etc/profile.d/
These files are executed upon login.
To create a symbolic link to the file you want to execute, use
sudo ln -s /home/karl/.scripts/startup/sensei-raw-startup.sh /etc/profile.d/myscript.sh
2. Using upstart
Another possibility is to use upstart
start on desktop-session-start
and place your script there.
Related videos on Youtube
Karl Morrison
Updated on September 18, 2022Comments
-
Karl Morrison almost 2 years
#!/bin/bash ids=$(xinput list | awk '/SteelSeries Sensei Raw Gaming Mouse .*pointer/ {print $8}' | sed 's/id=\(.*\)/\1/') if [ -z "$ids" ]; then exit 0; fi read -a ids_array <<< $ids echo fixing id ${ids_array[0]} xinput set-prop ${ids_array[0]} 'Device Accel Profile' -1 xinput set-prop ${ids_array[0]} 'Device Accel Constant Deceleration' 2.5 xinput set-prop ${ids_array[0]} 'Device Accel Adaptive Deceleration' 1 xinput set-prop ${ids_array[0]} 'Device Accel Velocity Scaling' 1 echo fixing id ${ids_array[1]} xinput set-prop ${ids_array[1]} 'Device Accel Profile' -1 xinput set-prop ${ids_array[1]} 'Device Accel Constant Deceleration' 1.5 xinput set-prop ${ids_array[1]} 'Device Accel Adaptive Deceleration' 1 xinput set-prop ${ids_array[1]} 'Device Accel Velocity Scaling' 1 sudo sensei-raw-ctl --show sudo sensei-raw-ctl --polling 500 sudo sensei-raw-ctl --cpi-on 450 sudo sensei-raw-ctl --cpi-off 5670 unset ids unset ids_array
I wish for the following script to run once when I login or when the computer starts up. The above script is located in
/home/karl/.scripts/startup/sensei-raw-startup.sh
.I DO NOT wish to use the GUI to add the script. I wish to learn a bit more about how to do it manually.
What files do I need to create, what must be in them and where should they be located to be able to run my script which is located in the said directory.
-
Julen Larrucea over 8 yearsHere they explain how to run an script at boot as root (in /etc/init) as user (/home/user/.config/upstart) or even with a "@reboot" task in cron: askubuntu.com/questions/814/how-to-run-scripts-on-start-up
-
mchid over 8 yearsEither rclocal or systemd on a newer system as seen in the posted link.
-
mcantsin over 8 years@Julen creating a cronjob is not the right solution, as @reboot starts the script when the system is started, not when the user logs in. help.ubuntu.com/community/CronHowto
-
-
Karl Morrison over 8 yearsHow does this handle sudo commands?
-
mcantsin over 8 years@KarlMorrison personally I think you should use the upstart solution, as /etc/profile.d is not really meant to be used like this. My suggestion is more a "hack". I you still want to try, just add the echo "password" in front of the | sudo -S part, whereafter sudo won't ask for the password any more.
-
Karl Morrison over 8 yearsIndeed I've tried: askubuntu.com/questions/704815/upstart-not-running-sh-script perhaps you could see whats wrong? :/
-
mcantsin over 8 years@KarlMorrison I think the error is with the part start on runlevel [2345]. Use the solution I suggest: start on desktop-session-start which I think is what you want: starting when the desktop session starts. - no? (Regarding upstart I will respond in your other ticket)
-
Karl Morrison over 8 yearsJust tried with what you suggested, still no effect :( I need the script to be loaded when the login screen appears (as the mouse can be used there). So basically before logging into the user.
-
mcantsin over 8 yearsPlease check in your related question: askubuntu.com/questions/704815/upstart-not-running-sh-script/…