crontab - schedule job to run every minute
I am setting crontab to run a script every minute irrespective of the current hour's value:
Code:
[root@localhost bin]# ls Any solutions? Does the line mean: "Run this script every day at hour:01"? |
Yes it does, for every minute use "*" in the first position
|
Quote:
and What should be for after every 12 hour? |
Probably easier if you check out some examples : http://adminschoice.com/crontab-quick-reference
cheers |
Quote:
Before I would check my post here, I had got the solution. I asked an Admin of UNIX here and he told me that *would be used "for every minute". */5 means every 5 minutes. Code:
*/5 * * * * /root/bin/showTime.sh Code:
*/60 * * * * /root/bin/showTime.sh Code:
*/60 */12 * * * /root/bin/showTime.sh I am going to put those lines in my crontab and will check the output when I come to office tonight. My shift is over. I am going now! |
For jobs to be run every 12 hour, this crontab entry didn't execute at all:
Code:
*/60 */12 * * * /root/bin/showTime.sh Code:
* */12 * * * /root/bin/at12.sh |
If this is on your local machine and not a remote server, you could be lazy and use a GUI called Gnome Schedule to set up the task for you.
According to the GUI, you need * * * * * 's to run a task every minute. |
Quote:
Why not just run the script one time (system startup?), and put a "sleep 60" statement in it, and loop back to the beginning?? That way, even if it takes 5 minutes to execute, it'll finish ONE loop, sleep 60 seconds, then run again, instead of cranking off 5 fresh copies... |
Quote:
GUI is for kids! No matter how many key strokes a command or task may require, I would prefer the old command line interface or console. Well, I am using PUTTY to login remotely on the server. |
Quote:
Well, in production servers we cannot reboot servers like that. Besides, running a job every minute is not what we (or at least I) would do. It is just a problem! Anyways, I have done it. Code:
*/59 * * * * /root/bin/at60.sh Code:
*/60 * * * * /root/bin/at60.sh |
Quote:
Quote:
Quote:
|
Quote:
We all have to start somewhere and if Linux was not so fiddly and picky, it may have a chance at kicking windows off the top slot... but it isn't. As for the comment, it was only a suggestion to solve a problem quickly, sometimes the method or means of performing a task are less important than the actual outcome. |
Quote:
I respect your age and experience, sir. Please, don't mind my comment. I am sometimes a kind of "showing-humour". Well, I agree to what you have said: Quote:
|
Quote:
|
Quote:
|
Ok. Indeed, I never considered an interval which is not a common divisor of 60. Just out of curiosity I tried the crontab on my system and it runs at 00 and at 59 minutes of every hour! It looks like cron starts the count at 00 minutes in any case and applies as many intervals as they fit in one hour. Does it work like this on your system? Thanks.
|
Quote:
Besides, those who think Code:
<time fields> sleep 30; someOtherCommandOrScript So, logically, I have not yet figured out how to shcedule a job to be executed every 30 seconds. |
Quote:
Write up a script/function to do what you want, then execute said script in the background, store the PID to a variable, then run sleep. At the end of of sleep run wait PID to see if the process finished. If it has not it will wait until that script has executed before continuing. You could also use pgrep to check to see if the process exist anymore, which would allow you to simply loop over the sleep command in a way such as (again, rusty from memory bash here): Code:
while true; do EDIT: Wouldn't <time fields> sleep 30; command execute sleep 30; command every second, simply delaying the execution of the command but actually running the line every second? |
Quote:
|
All times are GMT -5. The time now is 08:05 AM. |