Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash rc.local文件不工作raspberry pi_Bash_Raspberry Pi - Fatal编程技术网

Bash rc.local文件不工作raspberry pi

Bash rc.local文件不工作raspberry pi,bash,raspberry-pi,Bash,Raspberry Pi,这是我的/etc/rc.local文件的内容。它应该在我的raspberry pi上登录时运行,但它只是登录(因为我使用的是自动登录),然后什么也不做,也就是说,它只是带着pi@raspberrypi~$\u正在等待命令。我不知道为什么它不起作用,也不知道有没有bash脚本的经验 它应该挂载一个usb,然后在所述usb上运行一个文件,但它没有 #!/bin/sh -e # # rc.local # # This script is executed at

这是我的
/etc/rc.local
文件的内容。它应该在我的raspberry pi上登录时运行,但它只是登录(因为我使用的是自动登录),然后什么也不做,也就是说,它只是带着
pi@raspberrypi~$\u
正在等待命令。我不知道为什么它不起作用,也不知道有没有bash脚本的经验

它应该挂载一个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

我不知道raspberry pi,但您可以尝试在文件中写入一些内容,以查看文件是否正在运行。例如:

touch /tmp/test.txt
echo "$(date) => It's running" > /tmp/test.txt

如果它不工作,我知道在某些操作系统(例如fedora、rhel、centos)上,该文件的路径是
/etc/init.d/rc.local
。尝试此路径不需要任何费用;)

我想你是在运行Raspbian,它相当于Debian

rc.local
在登录前以root用户身份运行,因此您不需要或不想要
sudo
;它可能会导致错误,因此不会发生任何事情

任何用户登录时为其运行的用户级命令(与rc.local不同,rc.local在登录前运行)可以放入
/etc/bash.bashrc
。这可能更适合你的情况,至少是第二个命令


只能将pi用户的登录命令放入
/home/pi/.bashrc

我与RPi3/Jessie有完全相同的问题

我建议您在bashrc中启动脚本,方法是

sudo emacs /home/pi/.bashrc
就我而言,我在EOF上写道:

bash /home/pi/jarvis/jarvis.sh -b &

这在每次启动时都很有效。

我也有同样的问题。在Raspbian论坛中,解决方案是:

只需将第一行更改为
#/银行标识代码/sh-e

#!/bin/bash 

伊万X是对的。你不需要sudo命令。

这个技巧对我的树莓皮4B不起作用