Skip to content

Instantly share code, notes, and snippets.

@zz-jason
Created November 29, 2023 07:49
Show Gist options
  • Save zz-jason/e9087cd9db8f6f21d9dcd4438dcdcef7 to your computer and use it in GitHub Desktop.
Save zz-jason/e9087cd9db8f6f21d9dcd4438dcdcef7 to your computer and use it in GitHub Desktop.
Run a command periodically
#!/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