LoginSignup
0
1

時間を指定しコマンドやプログラムを実行する

Last updated at Posted at 2024-01-19

https://eng-entrance.com/linux-command-at
atコマンドについて詳しくまとめました 【Linuxコマンド集】
atは時間を指定しコマンドやプログラムを実行するコマンドだ。

ATでの設定

[whoamijc@0211developing work]$ at -t 202308151451
warning: commands will be executed using /bin/sh
at> date >> bbb.txt 2>&1
at> hogehoge >> bbb.txt 2>&1
at> <EOT>👈「<EOT>」を打つのではなく、「Ctrl➕D」で終了させる。
job 17 at Tue Aug 15 14:51:00 2023
[whoamijc@0211developing work]$

実行結果

[whoamijc@0211developing work]$ ll bbb.txt👈指定した日時にファイルが作られたことを確認
-rw-rw-r-- 1 whoamijc whoamijc 76 Aug 15 14:51 bbb.txt
[whoamijc@0211developing work]$ cat -n bbb.txt👈ファイルの中身を確認。「date」と「hogehoge」の実行結果が書き込まれている。
     1  Tue Aug 15 14:51:00 JST 2023
     2  /bin/bash: line 2: hogehoge: command not found
[whoamijc@0211developing work]$

標準出力・標準エラー出力とも1ファイルに出力可。
ターミナルをシャットダウンしても、ATで仕込んだコマンドは実行される。
sleep nで秒数指定も良いが、ターミナルがダウンすると実行されない。

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