Linux: Execute script on login

Autostart when logging in to Linux.

In my article “Setting up OneDrive on Linux with Rclone“, we created a script that allowed us to include OneDrive in Linux. This script always had to be executed manually.

In this article, we will look at how to run scripts and commands on Linux when the user logs in. Autostart for Linux.

Video description

Execute login script

We start with our script, which we want to run. The example is about OneDrive, but of course any other scripts and commands can be executed in this way. In the example, our script is called “” and is located in the home folder.

We can execute commands and scripts at login via the “.profile” file in the home folder. We edit the file with an editor of our choice.

vim ~/.profile

Here we can simply add our script or further commands by inserting them at the end.

In the example, we run our script “”. It is important that the command is not blocking, i.e. that it terminates. This should be tested before inserting it. This is the case with the OneDrive script, i.e. the execution hangs here. Thus, in the worst case, logging in is no longer possible.

In this case, it helps to add a “&” to the end of the command. This executes the command as a separate process. The command no longer blocks and the execution continues directly.

Done! When you log in, the command is now executed and OneDrive on Linux is automatically integrated.

Leave a Reply

Your email address will not be published. Required fields are marked *