1753436 Members
4703 Online
108794 Solutions
New Discussion юеВ

Re: Add a crontab job

 
SOLVED
Go to solution
hangyu
Regular Advisor

Add a crontab job

I want to add a crontab job , and this crontab job will be run 5 times for 1 minutes ( if set "* * * * *" , it only run 1 time for 1 minute ) , what can i do ? thx
8 REPLIES 8
Yogeeraj_1
Honored Contributor

Re: Add a crontab job

hi,

you can do it the hard way!

***** your_script; your_script; your_script; your_script; your_script;


hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor
Solution

Re: Add a crontab job

hi again,


or you can write another script so that it contains that commands 5 times inside!

vi script_run5times.sh
your_script; # run 1
your_script; # run 2
your_script; # run 3
your_script; # run 4
your_script; # run 5

then in your crontab:
***** script_run5times.sh

hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
hangyu
Regular Advisor

Re: Add a crontab job

thx reply ,

sorry , what my requirement is the crontab job run at every 20 seconds , can advise what can i do ? thx
Senthil Prabu.S_1
Trusted Contributor

Re: Add a crontab job

Hi,

Try this;
0,15,30,45 * * * * your script


Note:
I have not tried it on my machine.


HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Senthil Prabu.S_1
Trusted Contributor

Re: Add a crontab job

Hi,

Try this;
0,20,40,60 * * * * your script


Note:
I have not tried it on my machine.


HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Yang Qin_1
Honored Contributor

Re: Add a crontab job

You can re-write you script or create a new script like this:

#!/usr/bin/ksh

for myrun in 1 2 3
do
orig_script &
sleep 20
done

exit

and schedule it with crontab with "* * * * *"

Yang
Darren Prior
Honored Contributor

Re: Add a crontab job

Unfortunately cron can only schedule jobs on a minute by minute basis, not second by second.

You could run your script 5 times within another script with a sleep statement, but there's no guarantee that it will happen every 20 seconds.

regards,

Darren.
Calm down. It's only ones and zeros...
Peter Nikitka
Honored Contributor

Re: Add a crontab job

Hi,

it is not possible to do this directly with 'cron'. If you do not want to realize this in a script by yourself (as previous posterd recommended - as well as I), do this by five corntab entries:

* * * * * /path_to/myscript
* * * * * sleep 12; /path_to/myscript
* * * * * sleep 24; /path_to/myscript
* * * * * sleep 36; /path_to/myscript
* * * * * sleep 48; /path_to/myscript

Are you shure, one instance of 'myscript' is terminated before the next is started? You'll get loads of processes 'myscript'!

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"