Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo '--------------------'
- echo ' Work Time v1.1 '
- echo '--------------------'
- SECONDS_FILE='seconds.dat'
- TIMES_FILE='times.dat'
- convertsecs() {
- ((h=${1}/3600))
- ((m=(${1}%3600)/60))
- ((s=${1}%60))
- printf "%02d:%02d:%02d\n" $h $m $s
- }
- OPTION=exit
- function mainMenu {
- if [ -f "start" ]; then
- OPTION=$(whiptail --title "Work Time" --menu "Select operation" 20 60 12 \
- "stop" "Stop" \
- "times" "Time" \
- "clean" "Reset" \
- 3>&1 1>&2 2>&3)
- else
- OPTION=$(whiptail --title "Work Time" --menu "Select operation" 20 60 12 \
- "start" "Start" \
- "times" "Time" \
- "clean" "Reset" \
- 3>&1 1>&2 2>&3)
- fi
- }
- mainMenu
- estatus=$?
- if [ $estatus = 1 ]; then
- exit
- fi
- timestamp=$(date +%s)
- curtime=`date +%Y-%m-%d_%H:%M:%S`
- if [ $OPTION = "times" ]; then
- echo 'Times'
- cat times.dat
- res=`awk '{ sum += $1 } END { print sum }' $SECONDS_FILE`
- echo $res
- times=$(convertsecs $res)
- echo $times
- echo 'All times '$times > alltime
- whiptail --textbox alltime 12 80
- exit
- fi
- if [ $OPTION = "clean" ]; then
- zip $timestamp'.zip' $SECONDS_FILE $TIMES_FILE alltime start starttime
- rm -f $SECONDS_FILE $TIMES_FILE alltime start starttime
- echo 'Clean ok.'
- exit
- fi
- echo $timestamp
- echo $curtime
- if [ $OPTION = "start" ]; then
- echo 'Start Time'
- echo $timestamp > start
- echo $curtime > starttime
- exit
- fi
- if [ $OPTION = "stop" ]; then
- timestamp=$(date +%s)
- echo 'Stop Time'
- startstamp=`cat start`
- seconds="$((timestamp-startstamp))"
- starttime=`cat starttime`
- echo $starttime $curtime $seconds >> $TIMES_FILE
- echo $seconds >> $SECONDS_FILE
- rm -f start starttime
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement