Click here to Skip to main content
15,848,451 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Raspberry Pi4 Model B with buster os in it. I am trying to write a python script for running the webpage at bootup. On entering sudo nano /etc/xdg/lxsession/LXDE-pi/autostart in the terminal and adding @chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/ at the last line I can see the webpage at boot. But the problem is I need to do this with a python program. Have tried many scripts and it's not working. Every time It's throwing the error saying "No such file or directory: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart". I am attaching the script below. Please help me in solving this I am new to Raspberry Pi.

What I have tried:

Without adding sudo nano:
conf_file = /etc/xdg/lxsession/LXDE-pi/autostart

Python
def update_url():
       conf_file= '/etc/xdg/lxsession/LXDE-pi/autostart'
       try:
          with open(conf_file, 'w')as file:
             file.write('@chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/')

       except Exception as ex:
          print("Cant write dirctory:",ex)
          return 0
       finally:
           pass


Output:
Python
permission denied: /etc/xdg/lxsession/LXDE-pi/autostart


Adding sudo nano:
conf_file = sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Python
def update_url():
       conf_file= 'sudo nano /etc/xdg/lxsession/LXDE-pi/autostart'
       try:
          with open(conf_file, 'w')as file:
             file.write('@chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/')

       except Exception as ex:
          print("Cant write dirctory:",ex)
          return 0
       finally:
           pass


Output:
Python
No such file or directory: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Posted
Comments
Richard MacCutchan 20-Mar-22 12:57pm    
That filename is illegal, and you cannot include the "sudo nano" command in a start file. You need to edit your autostart file while in a privileged session. So enter "sudo nano" at the terminal and then try running the Python script. Although you could probably do this faster with a simple editor.
Abisheek Kumar 20-Mar-22 13:00pm    
Thank you for the reply. Sure I will try it.
k5054 20-Mar-22 13:48pm    
See my reply to Richard, RE sudo nano. Another option would be to change the file owner to root andset the suid execute bit on the python script- if python scripts obey the suid permission settings. It's not clear why you'd want to do this from a script, unless you're writing a PI setup/configure script to have an automated way of producing PI's that perform some task, e.g. an info Kiosk, that you need to have several instances of.
k5054 20-Mar-22 13:43pm    
I think you meant just enter "sudo myscript.py" at the terminal. sudo nano will start the nano editor in sudo mode, at which point you'd need to do CTL-T to get a "command to execute" prompt, all of which seems a bit overly complicated.
Richard MacCutchan 20-Mar-22 13:44pm    
Thanks, I wrote that without checking.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900