PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Countdown Timer Using A File On Linux Bash Script Example

Go down

Countdown Timer Using A File On Linux Bash Script Example Empty Countdown Timer Using A File On Linux Bash Script Example

Post by jamied_uk 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
jamied_uk
jamied_uk
Admin

Posts : 3016
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

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

Post by jamied_uk 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
jamied_uk
jamied_uk
Admin

Posts : 3016
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

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