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?

OS標準機能だけでジョブを単発スケジュール実行したい

Posted at

ログインしてなくても夜中に実行して、諸々の情報は勝手に揮発して欲しい。

Windows

Administrators で実行する

set sched=%time%
set yyyymmdd=%date:/=%
set name=job_%yyyymmdd%

rem 実行したい処理を TEMP に作る
echo echo 1 > %TEMP%\%name%.bat

rem 最後にタスクを削除する処理を入れておく
echo schtasks /delete /tn %name% /f >> %TEMP%\%name%.bat

rem 削除される名前でタスクを作成する
schtasks /create /tn %name% /tr %TEMP%\%name%.bat /sc once /st %sched% /sd %date% /ru SYSTEM  /f

ジョブの管理

rem 一覧を表示
schtasks /query | findstr job

rem 削除
schtasks /delete /tn %name%

powershell でタスク作っても良いが、手数が多くなってしまうので今回は cmd/bat で作った。

RHEL

伝統的な at を使うが、日付のフォーマットに癖があるので注意する

root で実行する。

sched=23:00
mmddyy=$(date +%m/%d/%y)
name=job_$(date +%F)

# 実行したい処理を /tmp に作成する
echo echo 1 > "/tmp/${name}.sh"

echo "/tmp/${name}.sh" | at $sched $mmddyy

ジョブの管理

# 登録したジョブの一覧を表示する
atq

# 削除する
atrm $id
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?