Last active
August 29, 2015 14:22
-
-
Save dvapelnik/3c0f0b9b7909be8f63de to your computer and use it in GitHub Desktop.
Run the command several times per minute
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 | |
# Script can start few command instances in one minute | |
# with automatic sleep and count per second | |
# Created for run multiple commands each mimute with cron on linux OS | |
# Author: Dmitry Vapelnik <dvapelnik@gmail.com> | |
# Created: 2015-06-01 23:26:43 | |
function help { | |
HELP="You must use two arguments: first - how many time to execute command in next minute; second - commant to execute" | |
echo -e $HELP | |
} | |
# Show help message | |
if [[ "$1" = "--help" || "$1" = "-h" ]]; then help; exit 0; fi | |
# Check count of arguments | |
if [[ ! "$#" = "2" ]]; then | |
echo You must specify count of executions per minute and command | |
exit 1 | |
fi | |
let "c = 60 % $1" | |
# Calculate sleep for each command | |
if [[ "$c" = "0" ]]; then | |
COUNT=$1 | |
let "SLEEP = 60 / $1" | |
else | |
echo "60 % $1: 60 is not divisible by the value of the first argument" | |
exit 1 | |
fi | |
for ((n=0;n<$COUNT;n++)) | |
do | |
bash -c "$2" & | |
sleep $SLEEP | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment