树莓派(raspberrypi)配置开机自启动

- 硬件

配置树莓派通电开机或重启后进入桌面环境时自动打开浏览器访问指定网址。
shumeipai.jpg


手动执行命令验证效果

root@raspberrypi:~# chromium-browser https://bi.example.com




配置开机自启动

编写脚本

将上面测试好的命令写入到 shell 脚本中,放到有权限执行的目录下。由于我这里树莓派开机后默认使用 admin 用户身份打开桌面环境,所以我把启动脚本放到 admin 用户家目录下。

root@raspberrypi:~# cat /home/admin/open_browser.sh
#!/bin/bash

sleep 30
chromium-browser https://bi.example.com
root@raspberrypi:~#

添加执行权限

root@raspberrypi:~# chown admin:admin /home/admin/open_browser.sh
root@raspberrypi:~# chmod u+x /home/admin/open_browser.sh
root@raspberrypi:~#


将脚本加入自启动

新增如下所示最后一行配置,执行上面创建好的脚本即可。

root@raspberrypi:~# vi /etc/xdg/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@sh /home/admin/open_browser.sh
root@raspberrypi:~#