shell循环处理小代码

383 阅读1分钟

shell循环小代码

目标:在给定的时间和间隔内,迭代指定的次数

#!/bin/bash

# the time of program to exec, the unit is second
# 程序执行的时常,单位是秒
program_time=$[ 3600*24 ]

# interval of program to run, the unit is second
# 程序执行的间隔,单位是秒
interval_time=5

# the iterations of code
# 程序迭代的次数
epoch=$[ ${program_time} / ${interval_time} ]

# the code for looping, content should be filled in here
# 将需要循环的代码放在这里面
function content() {
	echo "..."
}

for((i=0; i<${epoch}; i++))
do
	content;
	sleep ${interval_time};
done