如何使用 Raspberry Pi 3 在启动时制作 chromium 运行?

How can I make chromium run on startup using Raspberry Pi 3?

我有一个 Raspberry Pi 3 - B 型,带有 Raspbian jessie 操作系统。 我正在尝试在启动时打开 "chromium"。

我写了一个简单的脚本:

#!/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 也是:

我可以在我的任务管理器上看到 script1.sh 测试(它 运行 是 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

仍然对我不起作用:|

查看此问题的经过验证的答案... 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 &"

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

我做了一个小 hack...

我将这一行 @lxterminal 添加到此文件的末尾:

nano .config/lxsession/LXDE-pi/autostart

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

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

./home/pi/Desktop/script.sh

意思是:

  1. 每次启动 Raspberry Pi(第一个命令)时都会打开终端。

  2. 每次那个终端运行s,我的脚本也会运行(第二个命令)

它对我有用。 TNX 寻求帮助:)

将 shell 脚本路径直接添加到 ~/.config/lxsession/LXDE-pi/autostart(而不是 ~/.bashrc)效果更好。

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

改为在自动启动文件中试试这个:

@sh /home/pi/Desktop/script.sh &