I need to compute N operation (same operation) each hour.
For the moment I have my operations but I can’t understand execute it N time per hour:
#!/bin/bash
N=10;
# my operation
sleep 3600/${N}
Any suggestion?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, the way you have it written now, it will only perform “my operation” once, after which it will sleep for 6 minutes, and then exit. What you need is a loop construct around those two lines.
bashsupports several different loop constructs, but probably the simplest for this case would be:Of course, there’s no provision for terminating the loop in this case, so you’ll have to exit with
^Corkillor something. If you only wanted it to run a certain number of times, you could use aforloop instead, or you could have it check for the [non-]existence of a certain file each iteration and exit the loop when you create or remove that file. The most appropriate approach depends on the bigger picture of what you are really trying to do.