How can I repeat a command every interval of time , so that it will allow me to run commands for checking or monitoring directories ?
There is no need for a script, i need just a simple command to be executed in terminal.
You can use
Open Terminal and type :
change x to be the time you want .
For more help using the
For example : the following will list, every 60s, on the same Terminal, the contents of the Desktop directory so that you can know if any changes took place:
You can also use this command in terminal, apart from nux's answer :
This command will print output of
Use Ctrl+C to stop the process.
There is few drawbacks of
In the above circumstances this may appear as a better option.
Just wanted to pitch in to souravc and nux's answers:
Sounds like the ideal task for the
For example, if you would like to run a Python script on every Tuesday, 11 AM:
There are also some special names that replace the time, like
If you are monitoring the file system, then
In 1st terminal type this command :
Then in 2nd terminal, any command that affects the current directory,
Then in original terminal inotifywait will wake up and report the event
Or in a loop
You can create your own
First, open your
Second, paste these lines at the bottom of the file and save:
Third, either close and open again your terminal, or type:
Et voilà ! You can now use it like this:
you can use crontab. run the command
This will run your command every 10 minutes
This will run your command every 4 hours
Another possible solution
X number of times to repeat.
Y time to wait to repeat.
Another concern with the "watch" approach proposed above is that it does display the result only when the process is done. "date;sleep 58;date" will display the 2 dates only after 59 seconds... If you start something running for 4 minutes, that display slowly multiple pages of content, you will not really see it.
On the other hand, the concern with the "while" approach is that it doesn't take the task duration into consideration.
With this, the script will run sometime every minutes, sometime might take 1m40. So even if a cron will be able to run it every minutes, here, it will not.
So to see the output on the shell as it's generated and wait for the exact request time, you need to look at the time before, and after, and loop with the while.
This will output this:
As you can see, the command runs every minutes:
So just replace the "sleep
Shorter version without the debug lines: