LoginSignup
0
0

Linux at command 時刻を指定してコマンドを実行

Last updated at Posted at 2021-07-02
$ more shell_content.sh
                    
ls -l /path/to/my/directory/* |  mail -s "content of a directory" my-email@example.com 

$ more shell_send_status.sh

at now + 1   hours   -f shell_content.sh 
at now + 2   hours   -f shell_content.sh 
at now + 180 minutes -f shell_content.sh 
at 14:00Jul2         -f shell_content.sh

のようなファイルを用意しておいて

$ sh shell_send_status.sh

とすればよい。

上記の例では、1時間後、2時間後、3時間後(180分後)、「7月2日の14:00」にメールが送信される。

メールのタイトルは「content of a directory」

メールの本文は ls -l /path/to/my/directory/*  の内容となる。

計算が進んでアウトプットファイルが増える様子を定期的にメールでチェックできるので便利。

$ at -l

でどんな予定になっているか調べられる。

mail を送る際のmailコマンドのために、
mailutil
のようなものをインストールした気がする。

Reference 
https://askubuntu.com/questions/481816/why-my-at-clause-command-execute-the-shell-immediately-and-ignored-the-time-li

at のインストール

sudo apt install at

mailutils のインストール

sudo apt-get install mailutils
0
0
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
0