Hot answers tagged

206

This Answer is obsolete - and contains methods which were WRONG even when it was written. Unfortunately this still gets flagged as a Suggestion by StackOverflow. For running Midori on startup, take a look at this tutorial. For DIY solutions, read on. You can add your script executable command to the bottom of .bashrc that will run your script every ...


58

The way that I've seen most people do it (have a look on the Raspberry Pi forums), and have done myself with success is using /etc/rc.local. All you need to do here is put ./myscript in the rc.local text file. If it's in python, put python myscript.py. This literally is "a simple solution, (like dropping my script in some "startup" directory or something ...


39

Add it to the crontab The crontab runs commands at defined times. Edit the file: sudo crontab -e Add line to file (here a python script): @reboot python3 /home/pi/Desktop/exemple.py &


22

use timedatectl - for example sudo timedatectl set-timezone Australia/Sydney


16

Autostarting xorg apps If the script you want to start requires an xorg session then you might try following the freedesktop autostart spec which might or might not work depending on which desktop environment you are using. Alternatively, you can target your specific desktop environment as described at https://wiki.archlinux.org/index.php/autostarting. ...


16

how do I know what version of Python (2 or 3) I'm writing for Well, you should know because it is ultimately your decision! You pick one, you use the syntax of that particular generation, and you invoke the respective interpreter to run your script. If you have both versions installed they can typically be run using either python2 or python3. That's also ...


13

Use udev rules. find your device information. udevadm -a -p /dev/path/device/ KERNELS=="1-3" SUBSYSTEMS=="usb" DRIVERS=="usb" ... ATTRS{quirks}=="0x0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="SANDisk" ATTRS{product}=="USB DISK" ATTRS{serial}=="SD71011000019113" Then create your udev rules file for your device. When creating rules file, use ...


10

You can run any number of scripts with varying programming language. You can think in the direction of using tools like Screen or tmux. They basically are used to run scripts in background or detached mode. This proves to be quite useful when you have a lot of applications you need to keep track of whilst they are running in the background. Installation on ...


10

Assuming that you're not running a weird custom operating system with a minimal kernel, the RPi is running a full fledged version of linux. The applications it comes with are written in C, C++, Java, Perl, Python, and probably others. You'll have to install Julia, but there's no reason the RPi can't handle multiple languages.


9

First, if the script is run by a system daemon and that daemon is running with root privileges, you do not need to use sudo. This includes init (and systemd), which includes rc.local. If that daemon is not running with root privileges, then sudo will not work unless /etc/sudoers is configured to allow such (and without a password). Raspbian users may be ...


9

I use the following script to backup SD cards on OS X:- #!/bin/bash # script to backup Pi SD card # 2017-06-05 # 2018-11-29 optional name # DSK='disk4' # manual set disk OUTDIR=~/temp/Pi # Find disk with Linux partition (works for Raspbian) # Modified for PINN/NOOBS export DSK=`diskutil list | grep "Linux" | sed 's/.*\(disk[0-9]\).*/\1/' | uniq` if [ $...


8

I 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 ...


6

Try starting it this way at the beginning of /etc/rc.local: /full/path/to/myscript.js < /dev/null & & forks it into the background, presuming this is a persistent process. < /dev/null (redirecting standard input to ensure the handle stays open) is probably not necessary, but may make a difference. You need to use the absolute path in rc....


6

NEW METHOD - RASPBERRY PI OS. This should work on other versions too. Create a desktop file xyz.desktop type the following into it [Desktop Entry] Encoding=UTF-8 Type=Application Name=<Application Name Goes here> Comment= Exec= python /home/pi/Desktop/execute_on_boot.py StartupNotify=false Terminal=true Hidden=false paste this file into the /home/pi/...


6

I also had trouble with this. On the Raspberry Pi3 running Raspbian this is what I did: Create a startup shell script in your root directory (I named mine "launch"): sudo leafpad launch.sh Save the file Edit the LXDE-pi autostart file sudo leafpad /home/pi/.config/lxsession/LXDE-pi/autostart Add this to the bottom of that file ./launch.sh reboot


6

I second Shan-Desai's suggestion of tmux, which is great, but perhaps this is actually overkill for your application. If neither of the scripts is in some way interactive, requires user input etc., you can simply run them in parallel with Bash's & operator: $ julia myJuliaScript.jl & python3 myPythonScript.py This will keep the terminal “hanging” ...


6

A script is running without its interpreter when it is made executable and contains a shebang at the very first line. Because your script is running I assume that's the case with your script. But the error message shows that you miss the leading slash in the path to bash. Your shebang should look as follows: #!/bin/bash


6

If you are using systemd, just put your script to /lib/systemd/system-shutdown/ as described here and here. EDIT: If it's not working try this one: Create a systemd service: /etc/systemd/system/yourSript.service with following lines: [Unit] Description=yourScript [Service] Type=oneshot RemainAfterExit=true ExecStart=/bin/true ExecStop=/usr/local/bin/...


5

Use nohup ("no hangup"): nohup myscript.sh </dev/null 1>&2&> nohup.log & The </dev/null provides a standard input stream that won't close, since closing the that may confuse some things. This may or may not be necessary, since man nohup claims that's what it does anyway -- try it without and if that doesn't work, try it with. The ...


5

Ok, fixed it with the instructions below. I add this answer because this is quite specific (run when desktop is loaded). open up the file using nano: sudo nano /etc/xdg/lxsession/LXDE/autostart add the following line to the bottom of the file (just as last line) @sh /home/pi/myproject/myscript.sh save and reboot!


5

post-down script; Write a script to call 'reboot' as /path/to/script.sh Edit your /etc/network/interfaces file and add a line just below your eth0 config. auto eth0 iface eth0 inet static name "Ethernet0" address 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.254 post-down /path/to/script.sh Your /path/to/...


5

Raspian is basically Debian. Debian until and including Wheezy/7 used SysV, since Jessie/8 systemd. Upstart is not relevant anymore, since even RHEL and Ubuntu (the Upstart developers) have moved to systemd. systemd is very different from sysv. However, there is a compatibility layer in systemd that will transparently create units for properly annotated ...


5

@SteveRobillard answered my question in the comments. I will re-iterate it here for everyone to see clearly! 1. Viewing running programs: In the terminal type: ps aux | grep programname ps = display currently running processes a = show processes for all users u = display the process' user/owner x = show processes not attached to a ...


5

I would probably base it on the library I need to use. I would always try to stick with Python 3 as it is the new version, but if a library I need has not been upgraded/converted, then I'll have to use Python 2. Please see here for a list of Python libraries already converted to 3 and those yet to be.


5

You could use "Munin" with Raspbian to monitor your RPis. You need only one "Munin Master" and on each device you want to monitor, the "Munin Node" software. "Munin" is very flexible and comes with numerous plugins. But yet the setup process with Raspbian is fast and simple if you stick to the defaults. For the complete architecture please take a look at ...


5

Firstly: doing this by remote is inadvisable especially if, like me, you happen to be 70+ miles from your remote pi. It's a very long drive if you screw it up. When you do this fir the first time, do it "remotely" while sitting right next to the pi. Secondly: yes, this is possible but I've never done it and although I believe I could achieve it, I'm not ...


5

On Linux systems, there's a special file at /sys/class/net/$interface/carrier (where $interface is your interface name, e.g., eth0, wlan0). You can read from it like you would any other file in Python. If you read a 1, the interface is connected, and if you read a 0, it is not connected. Here's some untested example code to illustrate: def isConnected(...


5

You've run into a well-known limitation with cron. The question has been asked and answered here many times. This recent example highlights the two (at least two) choices you have: use cron (older, simpler) use systemd (newer, more complex) The answer to your question in the context of cron usage is this: If your script runs from the command line, but ...


4

You do call your script with a path in front, like /home/scripts/test1.sh or ./test1.sh, do you? What does ls -la /home/scripts/test1.sh say?


Only top voted, non community-wiki answers of a minimum length are eligible