linux - How to count time from current reference time -
i need build simple ksh/bash scrip or whatever on linux t know count time reference time
when type date command following:
date wed jul 17 18:13:27 idt 2013
or
[root@linux /var/tmp]# current_time=` date ` [root@linux /var/tmp]# echo $current_time wed jul 17 18:21:51 idt 2013
so here current date .
what need count example 10 min current date ,
so after 10 min print message
echo “sorry 10 min ended“
how count time reference time ?
use date +%s
unix time - number of seconds since 00:00:00 coordinated universal time (utc), thursday, 1 january 1970 - , use arithmetic expansion:
current_time=$(date +%s) elapsed_time=$(( $(date +%s) - $current_time ))
$elapsed_time
number of seconds since $current_time
. can check if $elapsed_time > 600
in loop.
edit: completeness:
if [[ $elapsed_time > 600 ]]; echo "sorry 10 min ended" fi
this should work in both bash , ksh.
Comments
Post a Comment