Advertisement
metalx1000

BASIC BASH Timer with Alarm

Sep 13th, 2018
1,555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2018  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #BASIC TIMER with ALARM
  7.  
  8. #This program is free software: you can redistribute it and/or modify
  9. #it under the terms of the GNU General Public License as published by
  10. #the Free Software Foundation, either version 3 of the License, or
  11. #(at your option) any later version.
  12.  
  13. #This program is distributed in the hope that it will be useful,
  14. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #GNU General Public License for more details.
  17.  
  18. #You should have received a copy of the GNU General Public License
  19. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20. ######################################################################
  21.  
  22. if [ $# -lt 1 ]
  23. then
  24.   echo "Time needed"
  25.   echo "Useage: $0 <seconds>"
  26.   echo "Example: $0 60"
  27.   exit 0
  28. fi
  29.  
  30. alarm="$HOME/.alarm.wav"
  31. time="$1"
  32. start=$SECONDS
  33. s=1
  34.  
  35. function main(){
  36.   echo "Welcome..."
  37.   while [ $s -gt 0 ]
  38.   do
  39.     s="$((time - (SECONDS - start)))"
  40.     echo -ne "\r                   \r"
  41.     echo -ne "\r$s seconds left"
  42.     sleep 1
  43.   done
  44.  
  45.   echo -e "\nTimes Up"
  46.  
  47.   if [ -f "$alarm" ]
  48.   then
  49.     play "$alarm" 2>/dev/null
  50.   else
  51.     for i in `seq 1 3`
  52.     do
  53.       play -n -c1 synth sin %-12 sin %-9 sin %-5 sin %-2 fade h 0.1 1 0.1 2>/dev/null
  54.     done
  55.   fi
  56.   exit 0
  57. }
  58.  
  59. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement