Countdown Timer Using A File On Linux Bash Script Example
Page 1 of 1
Countdown Timer Using A File On Linux Bash Script Example
This now also uses espeak so install that
- Code:
sudo apt install -y espeak
Give executable access
- Code:
sudo chmod +x *.sh
- Code:
#!/bin/bash
# (c) J~Net 2018
#
# jnet.forumotion.com/t1628-countdown-timer-using-a-file-on-linux-bash-script-example#2505
# ./countdown_file.sh
#
# Check if time file dont exists
COUNT=0
if [ ! -e time.txt ]
then
echo "Enter Time To Countdown In Seconds"
read myvar
echo "You Entered: $myvar"
echo "$myvar" > time.txt
fi
# Now get contents from a file
COUNT=`cat time.txt`
#
while [ $COUNT -gt 0 ]; do
clear
echo $COUNT
echo $COUNT | espeak
let COUNT=COUNT-1
sleep 1
clear
done
#
echo "GO!"
echo "GO!" | espeak
# Remove Timer
rm time.txt
#
#
# stackoverflow.com/questions/40082346/how-to-check-if-a-file-exists-in-a-shell-script/40082454
# unix.stackexchange.com/questions/404822/shell-script-to-create-a-file-if-it-doesnt-exist
Re: Countdown Timer Using A File On Linux Bash Script Example
Same But For Minutes
- Code:
#!/bin/bash
# (c) J~Net 2018
#
# jnet.forumotion.com/t1628-countdown-timer-using-a-file-on-linux-bash-script-example#2505
# ./countdown_Minute_file.sh
#
# Check if time file dont exists
COUNT=0
if [ ! -e time.txt ]
then
echo "Enter Time To Countdown In Minutes"
read myvar
echo "You Entered: $myvar"
echo "$myvar" > time.txt
fi
# Now get contents from a file
COUNT=`cat time.txt`
#
while [ $COUNT -gt 0 ]; do
clear
echo $COUNT Minutes Remaining
echo $COUNT | espeak
let COUNT=COUNT-1
sleep 60
clear
done
#
echo "GO!"
echo "GO!" | espeak
# Remove Timer
rm time.txt
#
#
# stackoverflow.com/questions/40082346/how-to-check-if-a-file-exists-in-a-shell-script/40082454
# unix.stackexchange.com/questions/404822/shell-script-to-create-a-file-if-it-doesnt-exist
Similar topics
» Linux Automation & Timers Bash Script Examples
» Bash Countdown Timer With Voice Output
» Make linux bash dot sh file executable shell script
» Linux BASH Script Running Commands and Functions From Bash Script and saving to varables
» Catch Keypress To Stop A Timer In Bash On Linux
» Bash Countdown Timer With Voice Output
» Make linux bash dot sh file executable shell script
» Linux BASH Script Running Commands and Functions From Bash Script and saving to varables
» Catch Keypress To Stop A Timer In Bash On Linux
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum