How to run a python script in a terminal upon login?

Aidan

I have my Debian virtual machine set to automatically login, and I want to make it so that, when the auto-login occurs, a terminal will open and run the command

python /home/pymodbus/examples/common/synchronous_client.py

The output from the python script occurs within the terminal, which is why I would like to open it in the first place. I have already done a lot of research, and have tried many things, including put this command in the /etc/rc.local file, but this did not appear to do anything.

Additionally, I tried this

gnome-terminal -e "python /home/pymodbus/examples/common/synchronous_client.py"

But this did not start the terminal upon login as I thought it would.

Does anyone have some insight into how to accomplish this? I am very new to Linux, and trying to figure out which packages and tools I need has been a very confusing experience!

Aidan

So I was able to figure out how to do this, and I wanted to share my findings here. Here're the steps I took:

  1. To get the command to run at startup, I edited the .bashrc file in /home/etc/ and put my command at the very end, after all the prewritten code (sudo python /home/usr/pymodbus/examples/common/synchronous_client.py). Make sure you have sudo in your command.
  2. To get the terminal to launch at startup, I created a desktop file in ~/.config/autostart (if you don't have the autostart folder, you can just create one).

  3. In the autostart folder, I created a .desktop file called gnome-terminal.desktop and populated it as follows:

    [Desktop Entry]
    Type=Application
    Exec=gnome-terminal
    Hidden=false
    NoDisplay=false
    X-GNOME-Autostart-enabled=true
    Name[en_NG]=Terminal
    Name=Terminal
    Comment[en_NG]=Start Terminal On Startup
    Comment=Start Terminal On Startup
    
  4. Finally, to bypass the need to type the sudo password when I wanted to run the script, I ran the command sudo visudo and put the following line at the very end of the file:

    <username> ALL=(ALL) NOPASSWD:ALL
    

I hope this helps anyone that might be attempting to do something similar to me!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to Make Script Run Upon Root Login [Lubuntu]

Run a Bash Script automatically upon login on Unix

How to run python script on terminal (ubuntu)?

How to run a terminal command inside a python script?

How can I properly run a shell script automatically upon login with my mac?

Python run script upon mail reception

How to run a script on Login

How to run a script upon IP change

Run my bash script on login and SEE terminal

How to run python script on terminal without using python3?

Run Python script on Mac terminal

How to run a Python script upon button click using mod_python without changing browser window

How to run this script in mac terminal?

How to run a script from terminal

How to run python script with library inside Kernell terminal?

How to run python script from Linux terminal every hour?

How to run Python script in a terminal window by double clicking it?

Run a Python Script on Login with Sudo

Run a python script from the python terminal in Python

Running script upon login mac

run a python script in terminal without the python command

Open the terminal in python and run a python script

How to launch a terminal from script and another script to run in terminal

How to Run Bash Script As Initialization Action Upon Creating Dataproc Cluster?

Lubuntu 20.04 Run a script at login which executes in a terminal window

Run bash script upon ssh

Run $Path command in Terminal in a python script

Run a Python script when opening Terminal(xterm)

Trying to run my python script in terminal