linux 时间计算脚本
来源:互联网 发布:t口数据线线序 编辑:程序博客网 时间:2024/05/01 14:19
#!/bin/bash
# User Defined Variables
# H,M,S 系統時間
# rhflag 0 = 當日, 1 = 明天, 2 = 後天...
# strUsage 參數提示訊息
# timeoffset 使用者輸入的時間 (時:分:秒)
# oh,om,os 從 timeoffset 提列出來的 時, 分, 秒 (case 1) / 進位值 (case 2)
# rh,rm,rs 運算結果 時, 分, 秒
# offset 使用 -h, -m, -s 參數時, 使用者帶入的數值
# System Variables
# $# 參數數量
# $0 Shell Script 檔名
# $1 第一個參數
# $2 第二個參數
H=`date +%H`
M=`date +%M`
S=`date +%S`
rhflag=0
strUsage="Usage:/n$0 hh:mm:ss/nor/n$0 [-h|-m|-s] number/n"
case "$#" in
1)
timeoffset=$1
oh=`echo $timeoffset | awk -F ':' '{print $1}'`
om=`echo $timeoffset | awk -F ':' '{print $2}'`
os=`echo $timeoffset | awk -F ':' '{print $3}'`
rs=`expr $S + $os`
if [ $rs -gt 59 ]; then
((rs -= 60))
om=`expr $om + 1`
fi
rm=`expr $M + $om`
if [ $rm -gt 59 ]; then
((rm -= 60))
oh=`expr $oh + 1`
fi
rh=`expr $H + $oh`
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
;;
2)
offset=$2
if [ $1 == "-h" ]; then
rh=`expr $H + $offset`
rm=$M
rs=$S
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
elif [ $1 == "-m" ]; then
rh=$H
rm=`expr $M + $offset`
rs=$S
if [ $rm -gt 59 ]; then
((oh = rm / 60))
((rm %= 60))
rh=`expr $H + $oh`
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
fi
elif [ $1 == "-s" ]; then
rh=$H
rm=$M
rs=`expr $S + $offset`
if [ $rs -gt 59 ]; then
((om = rs / 60))
((rs %= 60))
((rm += om))
if [ $rm -gt 59 ]; then
((oh = rm / 60))
((rm %= 60))
((rh += oh))
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
fi
fi
else
printf $strUsage
exit 1
fi
;;
*)
printf $strUsage
exit 1
;;
esac
if [ $rh -eq 24 ]; then
rh=0
rhflag=1
fi
echo "$H:$M:$S"
echo "$rhflag $rh:$rm:$rs"
# User Defined Variables
# H,M,S 系統時間
# rhflag 0 = 當日, 1 = 明天, 2 = 後天...
# strUsage 參數提示訊息
# timeoffset 使用者輸入的時間 (時:分:秒)
# oh,om,os 從 timeoffset 提列出來的 時, 分, 秒 (case 1) / 進位值 (case 2)
# rh,rm,rs 運算結果 時, 分, 秒
# offset 使用 -h, -m, -s 參數時, 使用者帶入的數值
# System Variables
# $# 參數數量
# $0 Shell Script 檔名
# $1 第一個參數
# $2 第二個參數
H=`date +%H`
M=`date +%M`
S=`date +%S`
rhflag=0
strUsage="Usage:/n$0 hh:mm:ss/nor/n$0 [-h|-m|-s] number/n"
case "$#" in
1)
timeoffset=$1
oh=`echo $timeoffset | awk -F ':' '{print $1}'`
om=`echo $timeoffset | awk -F ':' '{print $2}'`
os=`echo $timeoffset | awk -F ':' '{print $3}'`
rs=`expr $S + $os`
if [ $rs -gt 59 ]; then
((rs -= 60))
om=`expr $om + 1`
fi
rm=`expr $M + $om`
if [ $rm -gt 59 ]; then
((rm -= 60))
oh=`expr $oh + 1`
fi
rh=`expr $H + $oh`
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
;;
2)
offset=$2
if [ $1 == "-h" ]; then
rh=`expr $H + $offset`
rm=$M
rs=$S
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
elif [ $1 == "-m" ]; then
rh=$H
rm=`expr $M + $offset`
rs=$S
if [ $rm -gt 59 ]; then
((oh = rm / 60))
((rm %= 60))
rh=`expr $H + $oh`
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
fi
elif [ $1 == "-s" ]; then
rh=$H
rm=$M
rs=`expr $S + $offset`
if [ $rs -gt 59 ]; then
((om = rs / 60))
((rs %= 60))
((rm += om))
if [ $rm -gt 59 ]; then
((oh = rm / 60))
((rm %= 60))
((rh += oh))
if [ $rh -gt 24 ]; then
((rhflag = rh / 24))
((rh %= 24))
fi
fi
fi
else
printf $strUsage
exit 1
fi
;;
*)
printf $strUsage
exit 1
;;
esac
if [ $rh -eq 24 ]; then
rh=0
rhflag=1
fi
echo "$H:$M:$S"
echo "$rhflag $rh:$rm:$rs"
- linux 时间计算脚本
- sqlserver脚本时间计算
- 计算脚本运行时间(简易)
- Linux计算时间间隔
- linux计算时间
- linux计算时间
- linux 计算时间 time
- Linux下时间计算
- linux 计算时间 time
- Linux学习2之shell脚本计算代码段运行的时间(精确到毫秒)
- 一个计算脚本运行时间的类
- timer类,计算脚本的运行时间
- linux脚本中的时间处理
- linux时间和定时脚本
- PHP日期与时间的应用 计算脚本运行时间
- linux 计算程序运行时间
- linux计算程序运行时间
- linux 计算程序运行时间
- (11)《基于Linux的C编程与内核导读》--进程间管道通信(一)
- 备份与还原mysql数据库
- 说说我们开发中编写的文档 (转)
- rational rose下载安装及破解
- Linux常用指令
- linux 时间计算脚本
- 菜鸟从零开始做报表4-----点点滴滴
- 接上面的第二种配置方式
- 连接池和延迟加载
- TCP/IP协议详解(图)
- 如何用ATL的CRegKey类来操作注册表
- sizeof总结
- CDatabase中的open 与openEx的差别
- 什么是企业级项目开发 (转)