Created
November 29, 2023 07:49
-
-
Save zz-jason/e9087cd9db8f6f21d9dcd4438dcdcef7 to your computer and use it in GitHub Desktop.
Run a command periodically
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/bash | |
# Set the default period to 1 second | |
period=1 | |
# Parse the command line arguments | |
while getopts ":p:" opt; do | |
case ${opt} in | |
p ) | |
period=$OPTARG | |
;; | |
\? ) | |
echo "Invalid option: $OPTARG" 1>&2 | |
exit 1 | |
;; | |
: ) | |
echo "Invalid option: $OPTARG requires an argument" 1>&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND -1)) | |
# Execute the command periodically | |
while true; do | |
date | |
"$@" | |
echo -e "" | |
sleep "$period" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment