Login Items / Auto Start when Login

Dear All

What is the best way to launch a Script on the login ?

I have some rclone mounts ie some .sh files that I want to start when the machine logs in

Thanks

Do you mean login of a user, or when the system boots?

You can do either, but, the methods are vastly different based on what you actually want.

Lovely !

I was thinking as a user ?

But both would be educational :slight_smile:

Dear Auke,

Am I right by making a profile.d folder and placing the scripts in there ? For scripts when the user logs in ?

They are called systemd units.

You can create user systemd unit using

mkdir  -p ~/.config/systemd/user/

here there is an example of a unit:

$ cat ~/.config/systemd/user/example1.service 
[Unit]
Description=Example description

[Service]
Type=oneshot
ExecStart=/full/path/to/your/bash/script

[Install]
WantedBy=default.target

Then enable it to run when you login

systemctl --user enable example.service

if you want to execute a user script when the system boots then

sudo mkdir -p /etc/systemd/system/

and the service unit is

$ cat /etc/systemd/system/example2.service 
[Unit]
Description=Example 2

[Service]
Type=oneshot
User=YOUR_USER
WorkingDirectory=/home/YOUR_USER
ExecStart=/full/path/to/your/script 

[Install]
WantedBy=multi-user.target

to enable run:

sudo systemctl enable example2.service

you can find more information searching for systemd units.

Or the traditional way

adding your scripts to ~/.bashrc

Perfect !

Thank you guys for confirming nice and easy to follow