How to automatically execute a shell script when logging into Ubuntu

Solution 1:

You could simply add the following command into System > Preferences > Startup Applications:

bash /full/path/to/your/script.sh

That should do the trick ;)

Solution 2:

So basically, as nodiscc suggested, create a desktop launcher: ~/.config/autostart/script.desktop with the following contents:

[Desktop Entry]
Type=Application
Name=Autostart Script
Exec=autostart
Icon=system-run
X-GNOME-Autostart-enabled=true

Then create the autostart script: ~/bin/autostart with your bash contents:

#!/bin/bash
# Execute bash script below

Make sure that ~/bin/autostart is executable