Countdown Timer Using A File On Linux Bash Script Example

Go down

Countdown Timer Using A File On Linux Bash Script Example

Post by jamied_uk on 28th May 2018, 17:26



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
avatar
jamied_uk
Admin

Posts : 2439
Join date : 2010-05-09
Age : 35
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Countdown Timer Using A File On Linux Bash Script Example

Post by jamied_uk on 28th May 2018, 18:26

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
avatar
jamied_uk
Admin

Posts : 2439
Join date : 2010-05-09
Age : 35
Location : UK

http://address-shortner.co.uk

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum