Code: Select all
sudo nano /home/pi/.bashrcCode: Select all
echo Running at boot
sudo python /home/pi/sample.pyCode: Select all
sudo nano /home/pi/.bashrcCode: Select all
echo Running at boot
sudo python /home/pi/sample.pyYou should not be using sudo to edit and especially not to create files in the users home directory. If you create a file with sudo then it will be owned by root and may not work as expected.sonettguy wrote: ↑Sat May 12, 2018 10:05 pmNewbie here. I've got a RasPi Zero W running Rasbian GNU/Linus 9 with LXPanel 0.9.3. I used the following to auto-start a commonly known file, sample.py.Go to the last line of the script and add:Code: Select all
sudo nano /home/pi/.bashrcWhen I power the Pi, it launches the program. But, when I open Terminal on LXPanel, it launches the program again. This became a problem when I auto-started my own program which loops in the background. So, when I open Terminal, I get two looping programs competing with each other. Why is this happening and how can I prevent the act of opening Terminal from starting the program a second time?Code: Select all
echo Running at boot sudo python /home/pi/sample.py
Code: Select all
nano /home/pi/.config/lxsession/LXDE-pi/autostartCode: Select all
python /home/pi/sample.pyWhat does the script do? If it exits to the command line then the terminal will immediately close and you won't see anything.sonettguy wrote: ↑Sun May 13, 2018 2:47 amI didn't have an autostart file in that folder, so I created one. I cut & pasted the two command lines to start each program, removing the "sudo" from the front.but, now they don't start at all.Code: Select all
python /home/pi/sample.py
Code: Select all
@lxterminal -e python /home/pi/sample.pyI want to throw in my two cents, even though this is an old question but commonly asked to do simple thing - autostart. I tried all the suggested solutions in all the answers for this question. NONE of them worked for me. I am using Raspberry PI Model 2 with Raspbian.
The only way I could get my application to autostart successfully is through a script as follows. I say successfully because my application started as expected without having any issue like starting with wrong work path.
1.Create an empty file with extension .sh and name it whatever you want.
2.Copy and Paste the following EXACTLY except change "your application name" to the script name that you just created.3. Then, save the script file within your application folderCode: Select all
#! /bin/sh ### BEGIN INIT INFO # Provides: noip # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Simple script to start a program at boot ### END INIT INFO #change /direct/path/to/your/application to the path your application is in. cd /direct/path/to/your/application # example cd /home/pi/myprogram/ #change YourProgramExactName to Exact name of your program that you want to auto start ./YourProgramExactName exit 0
4. Then, open /home/pi/.config/autostart folder. It might be different in your case. Just open your home folder and enable view hidden folders. open .config/autostart. If you don't see autostart folder, then create a folder called autostart within .config folder.
5. within autostart folder you will need to create a shortcut to your script file that you created as follows. Create an empty file with extension .desktop.
6. Copy and paste the following in the empty desktop file except you will need to change Comment, Name, Exec, Path and Icon field's value.
[Desktop Entry]7. Save and close the file after changing all the necessary fields. You are done. Just test it out.Code: Select all
Comment= Exec=/path/to/Your/application/Name-of-the-script-file (.sh) Icon=/Path/to/Your/application/Icon/IconName Name=YourApplicationEXACTNAME Path=/Path/to/Your/Application-ONLY Type=Application
• note : this makes the script Debian LSBInit compliant:https://wiki.debian.org/LSBInitScripts
Just to clarify things, .bashrc doesn't run at boot. It's run when you start a bash shell so at login, every time you open a new terminal window, when you connect via ssh, etc.sonettguy wrote: ↑Sat May 12, 2018 10:05 pmNewbie here. I've got a RasPi Zero W running Rasbian GNU/Linus 9 with LXPanel 0.9.3. I used the following to auto-start a commonly known file, sample.py.Go to the last line of the script and add:Code: Select all
sudo nano /home/pi/.bashrcWhen I power the Pi, it launches the program. But, when I open Terminal on LXPanel, it launches the program again. This became a problem when I auto-started my own program which loops in the background. So, when I open Terminal, I get two looping programs competing with each other. Why is this happening and how can I prevent the act of opening Terminal from starting the program a second time?Code: Select all
echo Running at boot sudo python /home/pi/sample.py
If you are running the latest Raspbian Stretch with Desktop then the autorun should have already been created and located insonettguy wrote: ↑Sun May 13, 2018 2:47 amI didn't have an autostart file in that folder, so I created one. I cut & pasted the two command lines to start each program, removing the "sudo" from the front.but, now they don't start at all.Code: Select all
python /home/pi/sample.py
No. At least not that I've seen. That only happens when explicty configured to do so not out of the box.
I find yours mis-informed and/or trolling. None of the dozen plus linux boxes I have here automatically login in as any user on any device. All were installed with the default login settings. That box count includes several raspberry pi and debian boxes.
So, I'm nearly back to where I started, which was having a program boot and run properly (at least until I opened Terminal in Raspbian). Almost. Now, it seems, one of my programs no longer gets the time from the Internet. In fact, my Pi seems to have a new IP address. I wonder if doing all this caused me to lose my configuration along the way. I must leave that for another day...To use crontab with your Raspberry Pi to automate your programs, follow these steps:
1. Write your program and note down its location. We’ll be using a program called sample.py and save it at /home/pi/Desktop/.
2. Now open crontab. You may need to open crontab in root (add sudo before the command!).3. Add a new entry at the very bottom with @reboot to specify that you want to run the command at boot, followed by the command. Here we want to run the python program, so our entry isCode: Select all
crontab -e4. Now save the file and exit.Code: Select all
@reboot sudo python /home/pi/Desktop/sample.py /home/pi/Desktop/pyprog/log.txt
5. When you restart the pi, the command will be run. Be a bit careful with the permissions and making sure that your program runs properly before you put it on boot: you can waste a lot of time trying to figure out what went wrong!
Code: Select all
[Unit]
Description=stuff @ boot service
[Service]
ExecStart=/home/pi/python_to_run_at_boot.py
Restart=always
User=pi
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=stuff_at_boot
[Install]
WantedBy=multi-user.target
@Dougie, ignorance. Honestly, I can't even tell in your sample code what I am supposed to change to apply to my case.What's stopping you