bash rc.local 文件不工作树莓派
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23914382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rc.local file not working raspberry pi
提问by user2137452
This is the contents of my /etc/rc.local
file. It is supposed to run on login on my raspberry pi, yet it just logs in in (as I'm using auto login) and then does nothing, i.e. it just sits there with pi@raspberrypi ~$_
waiting for a command. I have no idea why it's not working nor any experience with bash scripts.
这是我的/etc/rc.local
文件的内容。它应该在我的 raspberry pi 上登录时运行,但它只是登录(因为我正在使用自动登录)然后什么都不做,即它只是坐在那里pi@raspberrypi ~$_
等待命令。我不知道为什么它不起作用,也不知道 bash 脚本的任何经验。
It should mount a usb then run a file on said usb but it doesn't.
它应该挂载一个 USB,然后在所说的 USB 上运行一个文件,但它没有。
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo /bin/mount /dev/sda1 /media/robousb
sudo python media/robousb/Robopython/usercode_old.py
exit 0
回答by Ivan X
I assuming you're running Raspbian, which is pretty much Debian.
我假设您正在运行 Raspbian,它几乎是 Debian。
rc.local
runs as root before login, so you don't need or want sudo
; it may be causing an error, hence nothing happening.
rc.local
登录前以 root 身份运行,因此您不需要或不想要sudo
;它可能会导致错误,因此什么也没有发生。
User-level commands that run for any user when they log in (unlike rc.local, which runs before login) can be put into /etc/bash.bashrc
. That may be more applicable to your situation, at least the second command.
登录时为任何用户运行的用户级命令(与 rc.local 不同,它在登录前运行)可以放入/etc/bash.bashrc
. 这可能更适用于您的情况,至少是第二个命令。
Login commands for the pi user only can be put into /home/pi/.bashrc
pi用户的登录命令只能放入 /home/pi/.bashrc
回答by Idriss Neumann
I don't know raspberry-pi but you could try to write something into a file to see if the file is running or not. For example :
我不知道 raspberry-pi,但您可以尝试将某些内容写入文件以查看该文件是否正在运行。例如 :
touch /tmp/test.txt
echo "$(date) => It's running" > /tmp/test.txt
If it doesn't work, I know that on some OS (fedora, rhel, centos for example), the path of that file is /etc/init.d/rc.local
. It doesn't cost anything to try this path ;)
如果它不起作用,我知道在某些操作系统(例如 Fedora、rhel、centos)上,该文件的路径是/etc/init.d/rc.local
. 尝试这条路不需要任何费用;)
回答by niackbuster
I have the exact same problem with RPi3/Jessie.
我对 RPi3/Jessie 有完全相同的问题。
I suggest you to launch your script in the bashrc by doing
我建议您通过执行以下操作在 bashrc 中启动您的脚本
sudo emacs /home/pi/.bashrc
In my case i wrote at the EOF:
就我而言,我在 EOF 上写道:
bash /home/pi/jarvis/jarvis.sh -b &
And that works well at each startup.
这在每个初创公司都运作良好。
回答by Boyan Kehayov
I have the same problem. In Raspbian forum is the solution:
我也有同样的问题。在 Raspbian 论坛中是解决方案:
Just change the first row from #!/bin/sh -e
to
只需将第一行从 更改#!/bin/sh -e
为
#!/bin/bash
Ivan X is right. You don′t need sudo command.
伊万 X 是对的。你不需要 sudo 命令。