I have really tried looking around but all the examples I find do not work for me.
I have a python script in a Raspberry Pi that starts using CRON....all good!
I would like to be able to debug the ouput that the script prints in screen from time to time so the "screen" command needs to be used to create a session and ensure that I can login and logoff using putty as needed.
I also add the "&" so it will run in background.
So currently I did:
1) Open cron
sudo crontab -e
2) Add the following line
#reboot python /home/pi/python/monitor.py &
This works correctly, I just need to know how to make a "screen" session open before launching the python script.
Thank you very much for your help!
Related
I first want to say I'm not too familiar with the linux system as a whole and am learning.
Anyway, I'm trying to figure out how to autorun a terminal command on boot without having to manually login via ssh and do it myself.
After logging in as Pi, the command I run is : screen -d -m pagekite.py 80 {my-website}
What is a nice and simple way to make this autorun on startup?
Thanks!
I made an app in Thonny that when I run it, shows a camera connected to RPI and shows the image in an interface. You can also use the keyboard to do some things in the interface, take photos, etc.
I always execute it using thonny (run button), but now, I am trying to autostart the program in python when Raspbian ends its starting (after a shutdown or reboot).
I tried to do it in 3 ways:
autostart
lxde-pi/autostart
crontab
But it doesn't work. It starts Raspbian, but nothing more. Any ideas or code to do it?
Thanks a lot.
This might be a bit late for #mash_10, but for anyone else who lands here my solution that auto fires a bash script on the home folder. To add new automatic startups I just add code to my personal bash script. This works on Buster rpi.
Details are in my answer here How to automatically launch python file once GUI has loaded on Raspbian Pixel
I'm writing a script that (basically) controls some motors from raspi gpio pins. I've been making it right for a while now, and when I boot the pi and run the program manually it works just fine. I also have a portion of the code that allows me to use my phone to connect via bluetooth and send some data to control the motors. That also works fine on a manual run of the program.
Now I am trying to make the program start automatically on boot, as this will eventually go in a larger machine (boat) and I won't be hooking a monitor etc. to it. I'm currently doing this through a cron job with the #reboot tag. Looks like this:
#This enables GPIO (as far as I know). The program fails without this command being run first.
#reboot sudo pigpiod
#This runs the python program. ampersand forks the process because it should run continuously.
#reboot python3 /home/pi/Desktop/BoatBrain.py &
#and this lets me connect my phone over bluetooth. The python program has
#a portion takes data from that connection. ampersand forks the process, which
#seems like the right thing to do, since it looks like it blocks other things.
#That is also why it is at the end of the cron table.
#reboot sudo rfcomm watch hci0 &
When I reboot, the jobs all run, and I can connect my phone, so it must have passed the line executing the python script, but the servo I have connected just jitters in place uncontrollably. Let me restate that when I take the cronjobs away and run this manually, the program works correctly with few to no jitters, so it doesn't feel like an electrical problem...
If you need any more information please let me know and I'll be happy to provide it. I have a tendency to leave things out without realizing XD
Thanks!
Did you add anything to ~/.profile? It might be why it works when you invoke the commands yourself. If so, create a file in sudo vi /etc/profile.d/servo.sh with the same couple lines you added to ~/.profile. Then the system will have those on reboot.
Also, you could put all the three commands in one shell script and just put the script in the crontab. then the script can control that they start in order. You could also have the cronjob write output to a logfile and then see what it says. Also you can check when the cron runs by looking in /var/log/syslog
Oh, also for testing, you can change #reboot to a start time like 10 * * * * and then you can get the cron working without having to reboot. Then later, change it back to #reboot to try it with reboot.
Either something is missing that your login has (.profile), the commands are starting too quickly at the same time and need to start in a controlled order or the system isn't completely ready yet, but I doubt that one.
I have a bash script that I've defined to run in startup, which runs a python script that waits for a command from another process, and when it gets it, it should open a chromium window with a certain URL.
When I run this script manually it works fine, but when the script runs from startup, I get an error (displayed in syslog):
Gtk: Can't open display
I guess that's because it's running in a startup mode so it doesn't actually have a display to "lean" on...
I was wondering if there's any way to get this work, anyway?
Thanks in advance
In your script that runs on startup try DISPLAY=:0 <command> &
To clarify DISPLAY=:0 simply sets which monitor your window opens on with 0 representing the first monitor of the local machine.
I'm relatively new to raspberry pi (5 days using it) and I've just finished to run my python script succesfully (called dogcare.py). Now I'm trying to execute this script right after my raspberry is turned on. I've been doing some research and I find different ways to do it:
using /etc/profile
using /etc/rc.local
using crontab
using /etc/init.d
using systemd
But none of these ways are working for me.
Setup enviroment:
Hardware: RaspberryPi 2 Model B
Software: Raspbian or NOOBs (not sure)
Context:
Since for my project I need to run meet.jit.si, I followed this guide http://www.instructables.com/id/Video-Calling-on-Raspberry-Pi-3/?ALLSTEPS and It has a step where sets chromium website to start right after RPi is turned on. (Currently this is working fine)
My python script is using request library in order to use HTTP GET with an external website application I've been working on.
Main problem:
I need to run both events: chromium website with meet.jit.si and my python script when my raspberry is turned on.
Current situation: chromium website is running after my RPi is turned on but my script doesn't.
I'd appreciate any help !
I have done a similar thing with my Raspi 2 as well which involved sending myself an email with the ip address of the pi so I could easily ssh/vnc to it.
My steps involved making a shell script which ran the python program.
#!/bin/sh
cd pythonfiledirectory
sudo python pythonfile.py
cd /
Then I made it executable with the following command:
chmod 777 file.sh
Now edit your crontab to run the file on startup.
In your terminal, type:
sudo crontab -e
Inside of the crontab write:
#reboot sh file.sh
You could add a log file if you wanted to debug and see why it's not working by making a log directory and changing the text you wrote in the crontab to:
#reboot sh file.sh >/logdirectoy/ 2>&1
This is what made it work for me and if it doesn't work try and make sure you can run your .sh file and try the crontab with some other files to debug the problem.