Digitra

LINUXサーバの設定やプログラムのことなどを中心にブログを書いています。

cronで1分以下の実行をさせる方法

sleepさせてから実行するプロセスを一気に作ってしまうことで実現します。

 

* * * * * for i in `seq 0 15 59`;do (sleep ${i} ; /path/to/script &> /tmp/script.log ) & done;

 

上の例だと、15秒おきに実行となる。

sleep 0 ; /path/to/script &> /tmp/script.log
sleep 15 ; /path/to/script &> /tmp/script.log
sleep 30 ; /path/to/script &> /tmp/script.log
sleep 45 ; /path/to/script &> /tmp/script.log

のプロセスが出来て、15秒おきの実行が実現できる。