Sponsored Content
Top Forums Shell Programming and Scripting Run a command for specific amount of time with an auto key press Post 302944228 by wisecracker on Sunday 17th of May 2015 05:27:26 PM
Old 05-17-2015
Again I am really not sure why you want the 'q' character so:-
OSX 10.7.5, default bash terminal..
Code:
#!/bin/sh
# key.sh
echo "q" > /tmp/q
read key < /tmp/q
echo "Character read is $key."
# TIMER should be 45, set to 1 for testing.
TIMER=1
# OFFSET should be 3600, set to 5 for testing.
OFFSET=5
COUNT=$(($(date +%s)+$OFFSET))
while [ $(date +%s) -le $COUNT ]
do
	if [ "$key" = "q" ]
	then
		echo "Run command(s) here."
		read -n1 -s -t$TIMER key
	else
		echo "Exiting loop manually..."
		break
	fi
done
echo "You are here!"
echo "Character is $key..."

Results:-
First letting the loop take its course.
Second pressing any key for quick exit.
Third pressing the q key several times.
Code:
Last login: Sun May 17 21:50:57 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./key.sh
Character read is q.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
You are here!
Character is q...
AMIGA:barrywalker~/Desktop/Code/Shell> ./key.sh
Character read is q.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Exiting loop manually...
You are here!
Character is p...
AMIGA:barrywalker~/Desktop/Code/Shell> ./key.sh
Character read is q.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
Run command(s) here.
You are here!
Character is q...
AMIGA:barrywalker~/Desktop/Code/Shell> _

This User Gave Thanks to wisecracker For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read line with a single key press...

I would really like to have a script that will accept the key press from the user with out having to press the enter key afterwards. i.e. echo "Press Y to print \c" read YesNo At this point the user has to press the enter key to continue. Is there a way to accept the key press from the... (3 Replies)
Discussion started by: jagannatha
3 Replies

2. UNIX for Dummies Questions & Answers

Capture an empty key press...

I am trying to test input from the user, if they press enter with out an Y or N. I have the characheter thing sorted but when it comes to a blank or empty key press I am having trouble. if ; then clear echo "Sorry, that is an invalid choice!" exit fi I am using a KSH script in... (3 Replies)
Discussion started by: jagannatha
3 Replies

3. Shell Programming and Scripting

Trap key press in a script

How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to quit if q is pressed. I have seen the traping the signal , but they give option only for traping the defined interrupt signals. But those does not help me here. (3 Replies)
Discussion started by: praveenbvarrier
3 Replies

4. UNIX for Dummies Questions & Answers

Run Command in Specific Time ...

Guy's I want to make script to run this command solevel every Saturday at 8:00 clock exactly . Can you please help me and teach me how to do this ... (9 Replies)
Discussion started by: IT Helper
9 Replies

5. Shell Programming and Scripting

Any key press causing logout from shell

Hi all! I have written a shell script which will invoke perl script infinitly in the background in a loop. Code will do as:Within while loop, perl script will be run in background, get the pid and notify pid in though mail. then wait for pid to be completed before going for next iteration. I am... (1 Reply)
Discussion started by: jramesh1
1 Replies

6. Shell Programming and Scripting

specific number jobs run at the same time

Hi, I have more that 100 jobs I can run background, if I want only 4 running at ther same time, how can I write a script to control it? Thanks peter (0 Replies)
Discussion started by: laopi
0 Replies

7. Shell Programming and Scripting

Generate specific amount of same characters

Hi, Is there a command to print one character x amont of times? I need for example 10 comma's (,,,,,,,,,,). Instead of creating a loop, I was wondering if there is a way to do this with sed or awk? Thanks! (3 Replies)
Discussion started by: Subbeh
3 Replies

8. Shell Programming and Scripting

Press Any Key script sequence using bash - HELP

hi to all. im a newbie in unix shell scripts. i want to make a simple unix shell script using the bash shell that asks a user to press any key after a series of commands, or an x if he wishes to exit. here's a sample script that i made: #!/usr/bin/bash pause(){ /usr/bin/echo "\t\t Press... (3 Replies)
Discussion started by: booghaw
3 Replies

9. Shell Programming and Scripting

How to detect key press in cgi shell script?

I want to detect key pressed in my .cgi web page, but it does not work even I found the code in other web site. My code is : #!/bin/sh #================================================= # PATH defination # ================================================... (2 Replies)
Discussion started by: Shuinvy
2 Replies

10. Shell Programming and Scripting

Script to run commands at a specific time.

Hello All, I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are 1. rm -rf /path/to/folder 2. mail the content of a file. How do i achieve this. Thanks. ... (4 Replies)
Discussion started by: Siddheshk
4 Replies
App::Prove::State(3)					User Contributed Perl Documentation				      App::Prove::State(3)

NAME
App::Prove::State - State storage for the "prove" command. VERSION
Version 3.28 DESCRIPTION
The "prove" command supports a "--state" option that instructs it to store persistent state across runs. This module implements that state and the operations that may be performed on it. SYNOPSIS
# Re-run failed tests $ prove --state=failed,save -rbv METHODS
Class Methods "new" Accepts a hashref with the following key/value pairs: o "store" The filename of the data store holding the data that App::Prove::State reads. o "extensions" (optional) The test name extensions. Defaults to ".t". o "result_class" (optional) The name of the "result_class". Defaults to "App::Prove::State::Result". "result_class" Getter/setter for the name of the class used for tracking test results. This class should either subclass from "App::Prove::State::Result" or provide an identical interface. "extensions" Get or set the list of extensions that files must have in order to be considered tests. Defaults to ['.t']. "results" Get the results of the last test run. Returns a "result_class()" instance. "commit" Save the test results. Should be called after all tests have run. Instance Methods "apply_switch" $self->apply_switch('failed,save'); Apply a list of switch options to the state, updating the internal object state as a result. Nothing is returned. Diagnostics: - "Illegal state option: %s" "last" Run in the same order as last time "failed" Run only the failed tests from last time "passed" Run only the passed tests from last time "all" Run all tests in normal order "hot" Run the tests that most recently failed first "todo" Run the tests ordered by number of todos. "slow" Run the tests in slowest to fastest order. "fast" Run test tests in fastest to slowest order. "new" Run the tests in newest to oldest order. "old" Run the tests in oldest to newest order. "save" Save the state on exit. "get_tests" Given a list of args get the names of tests that should run "observe_test" Store the results of a test. "save" Write the state to a file. "load" Load the state from a file perl v5.16.3 2013-05-02 App::Prove::State(3)
All times are GMT -4. The time now is 11:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy