-
-
Save lxr/958657cd237a191d1142 to your computer and use it in GitHub Desktop.
execute a command repeatedly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
delimiter='\ | |
' | |
interval=1 | |
while getopts d:i: opt; do | |
case $opt in | |
d) delimiter=$OPTARG;; | |
i) interval=$OPTARG;; | |
\?) exit 1;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
while sleep -- "$interval"; do | |
"$@" | sed ":a;\$!{N;s/\n/$delimiter/;ba;}" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAME | |
poll - execute a command repeatedly | |
SYNOPSIS | |
poll [-i interval] [-d delimiter] [command ...] | |
DESCRIPTION | |
The poll utility executes command at one-second intervals until | |
it fails. | |
The options are as follows: | |
-i interval | |
Set the execution interval (in seconds). | |
-d delimiter | |
Replace all newlines (except the last) in the output | |
of command with the delimiter string. Any forward | |
slashes and newlines in the string must be escaped with | |
backslashes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment