Advertisement
xeritt

Fixing working time

Apr 28th, 2023 (edited)
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.66 KB | Software | 0 0
  1. #!/bin/bash
  2. echo '--------------------'
  3. echo '   Work Time v1.1   '
  4. echo '--------------------'
  5. SECONDS_FILE='seconds.dat'
  6. TIMES_FILE='times.dat'
  7.  
  8. convertsecs() {
  9.  ((h=${1}/3600))
  10.  ((m=(${1}%3600)/60))
  11.  ((s=${1}%60))
  12.  printf "%02d:%02d:%02d\n" $h $m $s
  13. }
  14.  
  15. OPTION=exit
  16. function mainMenu {
  17.     if [ -f "start" ];  then
  18.         OPTION=$(whiptail --title  "Work Time" --menu  "Select operation" 20 60 12 \
  19.         "stop" "Stop" \
  20.         "times" "Time" \
  21.         "clean" "Reset" \
  22.         3>&1 1>&2 2>&3)
  23.     else
  24.         OPTION=$(whiptail --title  "Work Time" --menu  "Select operation" 20 60 12 \
  25.         "start" "Start" \
  26.         "times" "Time" \
  27.         "clean" "Reset" \
  28.         3>&1 1>&2 2>&3)
  29.    
  30.     fi
  31. }
  32.  
  33.  
  34. mainMenu
  35. estatus=$?
  36. if [ $estatus = 1 ];  then
  37.     exit
  38. fi
  39. timestamp=$(date +%s)
  40. curtime=`date +%Y-%m-%d_%H:%M:%S`
  41.  
  42. if [ $OPTION = "times" ];  then
  43.     echo 'Times'
  44.     cat times.dat
  45.     res=`awk '{ sum += $1 } END { print sum }' $SECONDS_FILE`
  46.     echo $res
  47.     times=$(convertsecs $res)
  48.     echo $times
  49.     echo 'All times '$times > alltime
  50.     whiptail --textbox alltime 12 80
  51.     exit
  52. fi
  53.  
  54. if [ $OPTION = "clean" ];  then
  55.     zip $timestamp'.zip' $SECONDS_FILE $TIMES_FILE alltime start starttime
  56.     rm -f $SECONDS_FILE $TIMES_FILE alltime start starttime
  57.     echo 'Clean ok.'
  58.     exit
  59. fi
  60.  
  61. echo $timestamp
  62. echo $curtime
  63.        
  64.  
  65. if [ $OPTION = "start" ];  then
  66.     echo 'Start Time'
  67.     echo $timestamp > start
  68.     echo $curtime > starttime
  69.     exit
  70. fi
  71.  
  72. if [ $OPTION = "stop" ];  then
  73.     timestamp=$(date +%s)
  74.     echo 'Stop Time'
  75.     startstamp=`cat start`
  76.     seconds="$((timestamp-startstamp))"
  77.     starttime=`cat starttime`
  78.     echo $starttime $curtime $seconds >> $TIMES_FILE
  79.     echo $seconds >> $SECONDS_FILE
  80.     rm -f start starttime
  81.     exit
  82. fi
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement