raspberryPIで電源投入時にスクリプトを実行する方法

投稿者: | 2022年4月17日

スクリプトを自動実行したい

毎回手動で自作のスクリプトを起動するのは面倒です。
そこで今回はraspberryPIを電源投入した時に自動でスクリプト実行する方法をご紹介します。

rc.localを編集

raspberryPIのコマンドラインを開き、rc.localを編集します。
ファイルの下の方に自分のスクリプトまでのPATHを追記します。
ここでは下記のように追記してます。(ご自身の実行したいスクリプトを追記ください)

/usr/bin/XXXXX ###任意のスクリプト

$vim /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"
  fi

  /usr/bin/XXXXX   ###任意のスクリプト

  exit 0

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です