如何使用Raspberry Pi 3在启动时运行铬?

时间:2016-11-08 14:30:52

标签: bash raspberry-pi raspbian

我有一个Raspberry Pi 3 - Model B,带有Raspbian jessie操作系统。 我试图打开"铬"在启动时。

我写了一个简单的脚本:

#!/bin/bash
/usr/bin/chromium-browser --noerordialogs --disable-session-crashed-bubble --disable-infobars --kiosk http://www.google.com
exit 0

我可以手动运行脚本,它可以正常运行。 我读了很多关于在启动时运行这个脚本的方法。 我试过了: 将此行@reboot path/to/my/script添加到crontab -e文件但没有成功 此外,我尝试通过添加以下行来编辑/etc/rc.local文件:

#!/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.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  /home/pi/Desktop/script1.sh&   <-------- THIS LINE 
fi
exit 0

我已检查过脚本是可执行文件还是rc.local:

  • rwxrwxrwx 1 pi pi script1.sh
  • rwxr-xr-x 1 root root rc.local

我可以在我的任务管理器上看到script1.sh tesk(它以root身份运行)但没有任何反应。

默认用户是Pi,我以Pi用户身份登录而不是root用户,也许这是问题所在? 有人可以解释一下问题是什么以及为什么我只能在任务管理器中看到脚本?我该怎么办 ? TNX!

更新 我已经将rc.local更改为:

!/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.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  su - pi -c "/usr/bin/chromium-browser --noerordialogs --disable-session-crashed-bubble --disable-infobars --kiosk http://www.google.com &"
fi
exit 0

对我来说仍然不起作用:|

3 个答案:

答案 0 :(得分:2)

我做了一招...... 它是这样的:

首先我将此行@lxterminal放在此文件的末尾:

nano .config/lxsession/LXDE-pi/autostart

它将在启动时自动启动终端。

然后我在文件末尾编辑了$ sudo nano .bashrc我添加了我的脚本路径。

./home/pi/Desktop/script.sh

这意味着终端将在每次启动Raspberry Pi(第一个命令)时执行,每次终端运行时脚本也会运行(第二个命令) 它为我工作。 TNX的帮助:)

答案 1 :(得分:1)

查看此问题的经过验证的答案...... Running Shell Script after boot on Raspberry PI

您似乎需要以用户pi运行脚本。

su - pi -c "/usr/bin/chromium-browser --noerordialogs --disable-session-crashed-bubble --disable-infobars --kiosk http://www.google.com &"

编辑:我错过了命令末尾的&

答案 2 :(得分:0)

将shell脚本路径直接添加到 @sh /home/pi/Desktop/script.sh & (而不是〜/ .bashrc)效果更好。

即每次终端会话(包括ssh)都不执行命令。

请在自动启动文件中尝试此操作:

  <system.webServer>
  <rewrite>
  <rules>
          <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
              <match url="^(.*)$" />
              <conditions>
                  <add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true"/>
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent"/>
          </rule>
      </rules>
  </rewrite>
相关问题