简体   繁体   English

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

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

I have a Raspberry Pi 3 - Model B, with Raspbian jessie operation system.我有一个 Raspberry Pi 3 - B 型,带有 Raspbian jessie 操作系统。 Im trying to open "chromium" on startup.我试图在启动时打开“铬”。

i wrote a simple script:我写了一个简单的脚本:

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

I can run the script manually and it works perfect.我可以手动运行脚本,它运行完美。 I read about a lot of various ways to run this script on startup.我阅读了很多在启动时运行此脚本的各种方法。 I have tried: adding this line @reboot path/to/my/script to crontab -e file with no success.我试过:将这一行@reboot path/to/my/scriptcrontab -e文件中,但没有成功。
Also i have tried to edit /etc/rc.local file by adding this line:我也尝试通过添加以下行来编辑/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

I have checked that the script is executable and rc.local too:我已经检查过脚本是可执行的,并且 rc.local 也是:

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

I can see script1.sh tesk on my Task Manger (it runs as root) but nothing happen.我可以在我的任务管理器上看到 script1.sh tesk(它以 root 身份运行),但没有任何反应。

The default user is Pi and i log as a Pi user and not as root, maybe this is the problem?默认用户是 Pi,我以 Pi 用户而不是 root 登录,也许这就是问题所在? Can someone explain me what is the problom and why i can see the script only in the Task Manager?有人可以解释一下什么是问题,为什么我只能在任务管理器中看到脚本? what should i do ?我该怎么办? TNX! TNX!

UPDATE i have changed the rc.local to be like:更新我已将 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

still does not work for me :|仍然对我不起作用:|

Check out the verified answer on this question... Running Shell Script after boot on Raspberry PI查看此问题的经过验证的答案... 在 Raspberry PI 上启动后运行 Shell 脚本

Looks like you need to run the script as the user pi .看起来您需要以用户pi身份运行脚本。

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

EDIT: I missed the & at the end of the command.编辑:我错过了命令末尾的&

I did a small hack...我做了一个小黑客...

I added this line @lxterminal to the end of this file:我将此行@lxterminal添加到此文件的末尾:

nano .config/lxsession/LXDE-pi/autostart

It will auto-start terminal on boot.它将在启动时自动启动终端。

Then I edited $ sudo nano .bashrc file.然后我编辑了$ sudo nano .bashrc文件。 At the end of the file, I added my path to my script.在文件的末尾,我将我的路径添加到我的脚本中。

./home/pi/Desktop/script.sh

It means that:这意味着:

  1. The terminal will open every time you boot your Raspberry Pi (first command).每次启动 Raspberry Pi 时终端都会打开(第一个命令)。

  2. Every time that terminal runs, my script will run also (second command)每次终端运行时,我的脚本也会运行(第二个命令)

It does work for me.它对我有用。 TNX for the help :) TNX 的帮助:)

Adding the shell script path directly to ~/.config/lxsession/LXDE-pi/autostart (not to ~/.bashrc) works better.将 shell 脚本路径直接添加到~/.config/lxsession/LXDE-pi/autostart (而不是 ~/.bashrc)效果更好。

Namely it does not execute the command every terminal session (including ssh).即它不会在每个终端会话(包括 ssh)中执行命令。

Try this in the autostart file instead:在自动启动文件中试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM