#!/bin/bash

# 打印函数
function print_red(){
    echo -e "\033[31m $* \033[0m"
}

function print_green(){
    echo -e "\033[32m $* \033[0m"
}

function print_yellow(){
    echo -e "\033[33m $* \033[0m"
}

function print_white(){
    echo -e "\033[37m $* \033[0m"
}

#1. Handle input parameters
CMD_NUM="$#"
if [ $CMD_NUM -lt 2 ];then
    print_red "Error: Parameters is not correct!"
    print_red "Usage: ./exeDelay.sh [Delay time(minutes)] [Action1] [Action2] [Action3] ..."
    exit 1
else
    DELAY_MIN=$1 # delay time
    index=0
    for arg in "$@"                     
    do
    if [ $index -eq 0 ];then
        print_yellow "Delay $DELAY_MIN minutes will execute commands :"
    else
        EXE_CMD[$index]=$arg # commands
        print_white "($index) -> ${EXE_CMD[$index]}"
    fi
     let index+=1
    done
    print_yellow "Wait..."
fi

#2. Start timer
while [ $DELAY_MIN -gt 0 ] 
do 
sleep 60
let DELAY_MIN-=1
print_yellow "Commands will execute after $DELAY_MIN minutes..."
done

#3. Execute commands
for ((i=1;i<=$CMD_NUM;i=i+1))
do
${EXE_CMD[$i]}
done

print_green 'Delay execute finish!!!'

 

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2021-08-27
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2023-02-03
  • 2021-06-24
猜你喜欢
  • 2022-02-25
  • 2021-12-04
  • 2021-09-14
  • 2021-09-08
  • 2021-06-19
  • 2022-01-03
相关资源
相似解决方案