工作过程中,为了监控状态,经常要不断地重复执行某个命令,因此写了个脚本来简化操作
#! /bin/bash # filename:redo.sh #usage: redo.sh [-d delaytime] [-c count] command #默认间隔时间为15s,无限循环执行 delay=15 count=-1 while getopts d:c: OPTION do case $OPTION in d) delay=$OPTARG ;; c) count=$OPTARG ;; esac done shift $(expr $OPTIND - 1) i=0 while [ $i -ne $count ] do clear echo "command:" $@ echo "count:" $i echo "delay:" $delay eval $@ i=$(expr $i + 1) sleep $delay done