npm install -g shell-interval
$ shell-interval -t 5 -c "echo Hello." -r 3Hello. # 0:05Hello. # 0:10Hello. # 0:15# [stop]
var shellInterval = ;;
shell-interval -c "[command]" -t 2 : Execute the
[command] every ~ two seconds indefinitely, until a kill signal is received. (e.g.
shell-interval -c "[command]" -t 5 -r 10 : Execute the
[command] every ~five seconds until the command has been called ten times, and then exit.
Command is first invoked ~five seconds after the call to
shell-interval -c "[command]" -t 5 -r 10 -e : Execute the
[command] every ~five seconds until the command has been called ten times, and then exit. Because the
--eager) flag was passed, the command is first executed as soon as node finishes initializing the script.
shell-interval module exports a single function with the same options as its command-line interface as well as hooks for two callbacks. These callbacks can handle data returned from the shell calls (
onExec) and perform any necessary cleanup after a finite series of shell calls has completed (
var shellInterval = ;var timeout_id =;
Arguments : A single hash of parameters with three properties.
options [object] : a hash of values corresponding to set-interval's CLI flags. Required.
command [string] : the shell command to execute. Required.
time [number] : the number of seconds between calls. Required.
reps [number] : a number of total shell calls to make. After this number is reached, the interval will be cleared. Optional.
eager [boolean] : whether to immediately execute the function once before starting the timer. Optional.
quiet [boolean] : when used with the default
onExec handler, tells set-interval not to print
stdout to the terminal. Optional.
onExec [function] : a callback to handle data returned from shell command execution. It is invoked once for each shell call and receives
stderr as its arguments. Optional.
onFinish [function] : when a limited number of repetitions is specified(in
options.reps), this callback is invoked after the last shell call has returned a value and been handled. Optional. Only has an effect if
reps is specified.
Return Value: a reference to the Node.js
timeoutId assigned to shell-interval's internal timer. This can be used with
clearInterval(<id>) to stop executing the shell command.
Both callbacks are optional, but the hash of parameters passed in must contain an
options itself must be a hash containing at least
;// echoes "Hello" in the terminal every five seconds// until a break signal is received.
More usefully, client code can supply two optional callback functions: one for each of the
onExecis invoked once for every execution of the shell command, and receives
stderras its arguments.
onFinishis only called if a finite number of repetitions has been specified (via
options.repsin node or
-r <number>in the shell). In this case it is called exactly once, after the last callback has returned its value and been handled. It does not receive any arguments.
onExec handler logs the shell response to the terminal unless the
--quiet flag is passed. Because this default handler is overridden by passing in a callback, the
--quiet flag will not affect the behavior of a client-provided function.
The function exported by
shell-interval returns the Node
timeoutId set by shell-interval internally, it can be used as a transparent replacement for a
setInterval call in many cases where periodic shell execution is needed. Most importantly, the return value can be passed to the normal
clearInterval function to stop executing the shell command.
var shellInterval = ;var intervalId =;
$ shell-interval -c "make" -t 10make: nothing to be done
npm install -g shell-interval
Use the GitHub issue tracker.
Pull requests are welcome. Include Mocha-compatible test specs and documentation of any changes to the API.
The MIT License (MIT)
Copyright (c) 2013 Scott Ivey, email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.