Sponsored Content
Top Forums Shell Programming and Scripting Stop! (the countdown!) :-) shell script help Post 302434389 by rich@ardz on Friday 2nd of July 2010 02:38:23 PM
Old 07-02-2010
Stop! (the countdown!) :-) shell script help

Hi guys, I've found two nifty little scripts on these forums one which detects if the F5 key has been pressed:

Code:
#/bin/sh
_key()
{
  local kp
  ESC=$'\e'
  _KEY=
  read -d '' -sn1 _KEY
  case $_KEY in
    "$ESC")
        while read -d '' -sn1 -t1 kp
        do
          _KEY=$_KEY$kp
          case $kp in
            [a-zA-NP-Z~]) break;;
          esac
        done
    ;;
  esac
  printf -v "${1:-_KEY}" "%s" "$_KEY"
}

_key x

case $x in
  $'\e[15~') echo You have pressed F5 ;;
esac

and one which does a countdown:

Code:
#/bin/sh
countdown=10
while [[ ${countdown} -ge 0 ]]
do
    #echo ${countdown}
    echo "${countdown} second(s) left"
    sleep 1
    countdown=$(( ${countdown} - 1 ))
done

What I'm trying to do is join these scripts together so that when my script runs, it does a countdown to 0 - once it gets to zero it calls a 'default' function I've written which uses non user specified parameter, but what I'd like is the user to be able to hit the F5 key if they like and 'stop' the countdown process - this will then call another function I've written which allows the user to input their own parameters. I can't seem to 'weld' the two scripts together however all attempts have failed Smilie mostly because I don't understand entirely how the key press script works? Does anyone see how I could do this? Cheers.

---------- Post updated at 07:38 PM ---------- Previous update was at 03:28 PM ----------

Does no one have any idea how to achive this Smilie

Code:
countdown=10
while [[ ${countdown} -ge 0 ]]
do
    
    echo "Automatic search using today's date will begin in ${countdown} second(s)." 
    echo "Press F5 to cancel and specify another date."
    sleep 1
    countdown=$(( ${countdown} - 1 ))
    
    if [[ $countdown == 0 ]]; then
        # run the automatic search using today's date
        # by calling the SearchAuto function
        SearchAuto
        fi
        
#more script needed here
#if key is pressed, cancel loop and call the manual search function

done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shell script - loop to countdown

I am taking a class in UNIX and have written a script that needs to countdown from a number that is read in from the keyboard to zero. If no number is given the start of the countdown should default to 10. I can't get this to do the default #! /bin/sh echo Enter a number here to countdown... (2 Replies)
Discussion started by: froggwife
2 Replies

2. Shell Programming and Scripting

stop Prstat using shell script

How to stop the Prstat using shell script ? because after i run the below script the thing seems to be always in loop and cannot get out till i ctrl + c, is there anything that i can add in the script to make it terminate ? <code> #!/bin/sh prstat -Tc -u testing > testing.txt </code> ... (19 Replies)
Discussion started by: filthymonk
19 Replies

3. UNIX for Dummies Questions & Answers

Stop a shell script

Hi, I am writing a bash shell script. How can I tell it to stop. For example, I would like to have something similar to the following: mike=1 if ; then STOP THE SCRIPT fi (3 Replies)
Discussion started by: msb65
3 Replies

4. Shell Programming and Scripting

How to stop asking password while running shell script?

Hello, I am ftping the file from one unix box to another box. This script works fine. Only problem here is, it is asking the password when ftp the file. How can i stop that. I am providing the password inside the shell script. But it is not accepting this. I need to put this script in crontab.... (5 Replies)
Discussion started by: govindts
5 Replies

5. UNIX for Dummies Questions & Answers

Script triggering Korn shell, how-to stop it?

Script_A.sh has echo "In am in script A" ksh ## K-shell is invoked. Script B.sh ## which I am writing... ./script_A.sh echo "I am in script B" return 0 When I run: $> Script_B.sh $> I am in script A $> Basically, on calling Script_A.sh from within Script_B.sh I have the issue of... (2 Replies)
Discussion started by: baivab
2 Replies

6. Shell Programming and Scripting

Help with stop/start Shell Script.

Hi All, I would like to develop a shell script for stop & start an application server (1-4) on Solaris box. Here are the user requirements for this task. 1. User will input the option which server they wish to stop. 2. Will clear cache files from specific location. 3. ... (1 Reply)
Discussion started by: venga
1 Replies

7. AIX

Shell script stop working

I have a strange problem. I have the following in a cron to find files older than a day. find /dir1/dir2/ ! -name . -prune -name "s*.txt" -type f -mtime +1 -exec echo {} \; | wc -w It was working fine for the last few days now it suddenly stopped working. I can clearly see files in the... (5 Replies)
Discussion started by: bbbngowc
5 Replies

8. UNIX for Dummies Questions & Answers

shell scripting - gives a message on Fridays and a countdown on other business days.

Hey - I need to write a shell script that gives a message on Fridays and a countdown on other business days. ("Today is Thursday, one day to go to Friday") I don't know if I should be scheduling a job for friday using the crontab command? Basically i'm totally lost. Any help would be greatly... (6 Replies)
Discussion started by: citizencro
6 Replies

9. Shell Programming and Scripting

Password in shell script for apps stop

Hi folks, I am running a shell script it asks for username and password to stop some service, I need to write some script that it will read username and password from my shell script and then sucessfully stop services without prompting username/password query. (13 Replies)
Discussion started by: learnbash
13 Replies

10. UNIX for Beginners Questions & Answers

How to stop a shell script if it encounters a error?

I am writing a bash shell script for GarazLab's "WP EMAIL CRAWLER - AUTO SCRAPER & REAL TIME EXTRACTOR". it contains some commands. I want to stop the shell execution as soon as it encounters an error. how to do it? (8 Replies)
Discussion started by: tahsin352
8 Replies
GAMECLOCK(6)							   Games Manual 						      GAMECLOCK(6)

NAME
gameclock - a simple game clock SYNOPSIS
gameclock DESCRIPTION
This manual page documents briefly the gameclock command. gameclock is a simple application designed to track the time spent thinking by the players during a chess game. Various ways of tracking time are supported, with only `countdown' (aka `blitz') and `fisher' for now. The graphical interface is keyboard driven and is intended to be minimal and simple. The code is made to be extensible to other game types. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (--). A summary of options is included below. -h, --help Show summary of options. This includes the program's version and license. -v, --verbose Show progress information to standard output. More `-v' will display more information: timestamps then game state engine. -f, --fullscreen Start the application in fullscreen mode. KEYBINDINGS
Most of the interface is keyboard-driven, apart from the initial clock and game configuration. space start the game / end turn shift keys end the turn, but only for the appropriate side (left or right side) p pause game control-r, escape reset game - this resets all counters and clocks to the initial configuration, use this to restart the game. f toggle the fullscreen mode control-q quit application SEE ALSO
xboard(1), http://gnomecoder.wordpress.com/chessclock/. AUTHOR
gameclock was written by Antoine Beaupre. August 13, 2008 GAMECLOCK(6)
All times are GMT -4. The time now is 01:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy