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
XDaliClock(1)                                                 General Commands Manual                                                XDaliClock(1)

NAME
xdaliclock - melting digital clock SYNOPSIS
xdaliclock [-toolkitoption ...] [-option ...] DESCRIPTION
The xdaliclock program displays a digital clock; when a digit changes, it ``melts'' into its new shape. This program was inspired by the Alto and Macintosh programs of the same name, written by Steve Capps in 1983 or 1984. OPTIONS
xdaliclock accepts all of the standard toolkit options, and also accepts the following options: -help Print a brief summary of the allowed options on the standard error output. -12 Use a twelve hour clock. -24 Use a twenty-four hour clock. -seconds Update every second. -noseconds Update once per minute; don't display seconds at all. -cycle Do color-cycling. -nocycle Don't do color-cycling. -font fontname Specifies the X font to use; xdaliclock can correctly animate any font that contains all the digits plus colon and slash, and in which the letters aren't excessively curly. The xdaliclock program also contains four builtin bitmapped fonts, which are larger and more attractive than the standard X fonts. One of these fonts will be used if the -font option is given one of the fontnames BUILTIN0, BUILTIN1, BUILTIN2, or BUILTIN3. -builtin0 This is the same as specifying -font BUILTIN0. -builtin1 This is the same as specifying -font BUILTIN1. -builtin2 or -builtin This is the same as specifying -font BUILTIN2. -builtin3 This is the same as specifying -font BUILTIN3. -fullscreen Make the window take up the whole screen. When -fullscreen is specified, the displayed time will wander around a little, to pre- vent any pixels from being on continuously and causing phosphor burn-in. -root Display the clock on the root window instead of in its own window. This makes the digits wander around too. -window-id window Render the clock on a window created by some other program. -visual visual Specify which visual to use. Legal values are: default Use the screen's default visual (the visual of the root window.) This is the default. best Use the visual which supports the most writable color cells. class One of StaticGray, StaticColor, TrueColor, GrayScale, PseudoColor, or DirectColor. Selects the deepest visual of the given class. number A number (decimal or hex) is interpreted as a visual id number, as reported by the xdpyinfo(1) program; in this way you can select a shallower visual if desired. If you don't have a 24-bit system, using a visual other than the default one may cause colormap flashing. -transparent Causes the background of the window to be transparent, if possible. If the server supports overlay planes, then they will be used (this is the case on SGIs, and on certain HP, DEC, and IBM systems.) If overlay planes are not available, but the server supports the Shape extension, then that will be used instead. However, the Shape extension is very inefficient: it will cause your X server to use up a lot of cycles. Also, if the Shape extension is used, you will probably need to configure your window manager to not put a titlebar on the XDali- Clock window. (This is the case at least with twm, tvtwm, and mwm.) If you don't do this, then the window will flicker con- stantly, as the window manager tries to add and remove the titlebar ten times each second. None of these problems occur if overlay planes are used (or if the -transparent option is not requested.) -nontransparent Don't make the window's background be transparent. This is the default. -memory low Use high-bandwidth, low-memory mode. If you have a very fast connection between the machine this program is running on and the X server it is displaying on, then xdaliclock can work correctly by simply making the drawing requests it needs when it needs them. This is the elegant method. However, the amount of data necessary to animate the display ends up being a bit over 10 kilobytes worth of X Protocol per second. On a fast machine with a local display, or over a fast network, that's almost negligible, but (for example) an NCD X Terminal at 38.4 kbps can't keep up. That is the reason for: -memory medium Use high-memory, low-bandwidth mode. In this mode, xdaliclock precomputes most of the frames that it will ever need. This is the sleazy copout method. The bandwidth requirements are drastically reduced, because instead of telling the server what bits to draw where, it merely tells it what pixmaps to copy into the window. Aside from the fact that I consider this to be cheating, the only downside of this method is that those pixmaps (about 170 of them, each the size of one character) are consuming server-memory. This probably isn't a very big deal, unless you're using an exceptionally large font. -memory high With memory set to high, the cache is twice as large (the n -> n+2 transitions are cached as well as the n -> n+1 ones). Even with memory set to medium, this program can seem sluggish when using a large font over a very slow connection to the display server. -countdown date Instead of displaying the current time, display a countdown to the specified date (if the date has already passed, count up from it.) The date can take two forms: either a time_t (an integer, the number of seconds past "Jan 1 00:00:00 GMT 1970"); or, a string of the form "Mmm DD HH:MM:SS YYYY", for example, "Jan 1 00:00:00 2000". This string is interpreted in the local time zone. To count up from the current time, do this: xdaliclock -countdown "`date '+%b %d %T %Y'`" The following standard X Toolkit command line arguments are commonly used with xdaliclock: -display host:dpy This option specifies the X server to contact. -geometry geometry This option specifies the preferred size and position of the clock window. -bg color This option specifies the color to use for the background of the window. The default is ``white.'' -fg color This option specifies the color to use for the foreground of the window. The default is ``black.'' -bd color This option specifies the color to use for the border of the window. The default is the same as the foreground color. -rv This option indicates that reverse video should be simulated by swapping the foreground and background colors. -bw number This option specifies the width in pixels of the border surrounding the window. -xrm resourcestring This option specifies a resource string to be used. COMMANDS
Clicking and holding any mouse button in the xdaliclock window will cause it to display the date while the button is held. Typing ``space'' at the xdaliclock window will toggle between a twelve hour and twenty-four hour display. Typing ``q'' or ``^C'' at the window quits. If the xdaliclock window is iconified or otherwise unmapped, it will go to sleep until it is mapped again. X RESOURCES
xdaliclock understands all of the core resource names and classes as well as: mode (class Mode) Whether to display 12-hour or 24-hour time. If 12, this is the same as the -12 command line argument; if 24, this is the same as -24. datemode (class DateMode) Specifies how the date should be printed when a mouse button is held down. This may be one of the strings mm/dd/yy, dd/mm/yy, yy/mm/dd, yy/dd/mm, mm/yy/dd, or dd/yy/mm. The default is mm/dd/yy. If seconds are not being displayed, then only the first four digits will ever be displayed (mm/dd instead of mm/dd/yy, for example.) seconds (class Seconds) Whether to display seconds. If true, this is the same as the -seconds command line argument; if false, this is the same as -nosec- onds. cycle (class Cycle) Whether to do color cycling. If true, this is the same as the -cycle command line argument; if false, this is the same as -nocy- cle. font (class Font) The same as the -font command line option: the font to melt. If this is one of the strings BUILTIN0, BUILTIN1, BUILTIN2, or BUILTIN3, then one of the large builtin fonts will be used. Otherwise, this must be the name of a valid X font. fullScreen (class FullScreen) The same as the -fullscreen command-line option. root (class Root) The same as the -root command-line option. visualID (class VisualID) The same as the -visual command-line option. transparent (class Transparent) Whether to make the window's background be transparent, if possible. If true, this is the same as the -transparent command line argument; if false, this is the same as -nontransparent. memory (class Memory) This must be high, medium, or low, the same as the -memory command-line option. countdown (class Countdown) Same as the -countdown command-line option. ENVIRONMENT
DISPLAY to get the default host and display number. XENVIRONMENT to get the name of a resource file that overrides the global resources stored in the RESOURCE_MANAGER property. TZ to get the current time zone. If you want to force the clock to display some other time zone, set this variable before starting it. For example: sh: TZ=GMT0 xdaliclock csh: ( setenv TZ PST8PDT ; xdaliclock ) You may notice that the format of the TZ variable (which is used by the C library ctime(3) and localtime(3) routines) is not actually documented anywhere. The fourth character (the digit) is the only thing that really matters: it is the offset in hours from GMT. The first three characters are ignored. The last three characters are used to flag daylight savings time: their presence effectively adds 1 to the zone offset. (I am not making this up...) BUGS
Other system load will sometimes cause the second-display to increment by more than one second at a time, in order to remain synchronized to the current time. The -memory option is disgusting and shouldn't be necessary, but I'm not clever enough to eliminate it. It has been said that hacking graphics in X is like finding sqrt(pi) with roman numerals. When using a small font (less than 48x56 or so) it's possible that shipping a bitmap to the server would be more efficient than sending a DrawSegments request (since the endpoints are specified using 16 bits each, when all that we really need is 6 or 7 bits.) Support for the Shared Memory Extension would be a good thing. It should display the day of the week somewhere. The color cycling should be less predictable; it should vary saturation and intensity as well, and should be more careful that foreground and background contrast well. The correct default datemode should be extracted from the current locale. Should have a -analog mode (maybe someday...) UPGRADES
The latest version can always be found at http://www.jwz.org/xdaliclock/ There is a version of this program for PalmOS available there as well. SEE ALSO
X(1), xrdb(1), xlsfonts(1), xclock(1), dclock(1), oclock(1), tclock(1), xscreensaver(1) COPYRIGHT
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2002 by Jamie Zawinski. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. AUTHOR
Jamie Zawinski <jwz@jwz.org>, 18-sep-91. Please let me know if you find any bugs or make any improvements. Thanks to Ephraim Vishniac <ephraim@think.com> for explaining the format of the bitmap resources in the Macintosh version of this, so that I could snarf them for the -builtin3 font. And thanks to Steve Capps for the really great idea. X Version 11 11-Sep-2002 XDaliClock(1)
All times are GMT -4. The time now is 03:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy