Linux shell脚本 执行时间戳定时器

Linux shell脚本 执行时间戳定时器

Linux学习小结 1


shell 脚本

代码如下(示例):

#!/bin/bash

#时间戳定时器

TIME_LOG='timer.log' #文件运行开始的文件
echo "time start value: \c" #打印
date '+%s' > $TIME_LOG  #时间重定向到文件,%s为时间秒
cat $TIME_LOG  
timer_start=$(cat $TIME_LOG)

while true #循环
do
    now=$(date +%s) #获取当前时间
    timeout=`expr $now - $timer_start` #计算时间差 

if test $timeout -gt 10  #超时时间计算
then
    echo "TIMEOUT!"
    exit
else
    echo "$timeout" 
 fi
sleep 1 #延时
done 

猜你喜欢

转载自blog.csdn.net/weixin_45023644/article/details/115386389