ラズベリーパイを使ってみる – 1時間に1回のような、定期的にすることをプログラムする!準備編(crontab) –

スポンサーリンク

コンテンツ

ラズベリーパイで動作確認済です!

crontabとは

「crontab」プログラムは、ラズベリーパイで定期的な処理をするときに使用するものです。

インストール

ラズベリーパイでcrontabプログラムは最初からインストールされているので、すぐに使うことができます!

プログラムの実行例

このプログラムは、以下のように使用します。

crontab -e

それではラズベリーパイで実行してみましょう。

実行

crontab -e

no crontab for pi - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/vim.basic
  4. /usr/bin/vim.tiny

Choose 1-4 [2]: 

crontabプログラムによって、ラズベリーパイで定期的に行われる処理を編集しようとしました。
crontabプログラムでは、定期的な処理をエディタで記述する必要があります。その時のエディタを選択する必要があります。
ここでは、世界で多く使われているエディタ「vim」を使用します。キーボードから「3」を入力し「ENTER」ボタンを押します。

すると以下のような画面になります

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
"/tmp/crontab.Tx3Sgk/crontab" 22L, 888C      

以上です。crontabプログラムを起動することで、ラズベリーパイで定期的に行う処理の編集が開始されました。
次の記事で、具体的に定期的に行う処理を書いていこうかと思います!!

「crontab」にはいろいろな使い方があります。記事を読むだけでなく手を動かして調べてみると、コンピュータを具体的に学ぶ良い経験になります!!