0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cronでシェルスクリプトを実行する

Posted at

はじめに

cronでシェルスクリプトを実行するタスクがあり、色々コマンドを実行したため備忘録を残します。

cronとは

cronとはスクリプトを自動で実行してくれるデーモンプロセスです。
決まった命令をこの時間に実行して欲しいという場合に有効で、バッチ処理に似たような処理と認識しています。

今回はデータベースの古いファイル(3日前以前)を夜間4時に削除するというシェルスクリプトを作成しました。

cron実行

cron実行までの流れ

まずはcron登録

cronを実行するにはcrontabへ実行したいファイルを新規に登録します。

$ crontab -e

実行するとviエディタが開くので、キーボードのiを押してINSERTモードにします。
今回はsample.shファイルを早朝4時に実行するという命令をcrontabに登録しました。

04 00 * * * /root/bin/sample.sh
~
~
~
~
~

登録後は:wqで保存し終了します。

実行時間のコマンドなどは以下のページを参考にしました。

「クーロン(cron)をさわってみるお」 https://qiita.com/katsukii/items/d5f90a6e4592d1414f99

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?