I have a cron properties file and some of the properties contain expression like:
"* 0/5 * * * ?"
and some of them contain:
"* */5 * * * ?"
What is the difference between the two?
If I want to run every 5 minutes then which one should be used?
Thanks
PS: My project is using spring scheduler.
You can use "*/5 * * * * *" for every 5 minutes and 0 0/5 8-10 * * * for every 5 minutes between 8 o'clock and 10 o'clock
For more info read this
Related
I have a cron job with below details
The timing section is unknown, it might be hourly or daily.
cat zyx.txt
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 * * * * root /usr/local/bin/log-cleaner
I have to update it on the fly using sed, so that it should run every minute .
Here is what I have tried
sed -in 's/\(.*\) \(.*\) \(.*\)/\* \* \* \* \*/1' zyx.txt
But it is removing the user and path section
cat zyx.txt
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * *
Any help / suggestion using sed is much appreciated
i use fallowing command to excute my script in every 30 min
*/30 * * * * /home/g-m-iqbal/Desktop/Auto/algo.sh
and also try this
*/30 * * * * /home/g-m-iqbal/Desktop/Auto/ && sh algo.sh
here
/home/g-m-iqbal/Desktop/Auto this the path of script
So i have simple shell commands to ping websites to retrieve data about said websites.
For example one of my pinging.sh looks like this:
ping -R -c 120 blar.org.cn >> pingdata.txt
ping -R -c 120 another.net >> pingdata.txt
But then my crontabs look like this:
7 * * * ./pinging.sh >> pingdata.log
The pingdata.log doesn't output. Is it best to do it through the crontab or through the script? I assumed the crontab would be better because it would cover the entire script rather than having to write it out multiple times.
You need to indicate the full path of your script in the cronjob, together with the binary running it.
For example:
7 * * * * /bin/sh /home/you/pinging.sh >> /home/you/pingdata.log
Note also you are just adding 4 parameters to the cronjob, whereas you need at least 5:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
You can test your cron syntax with Crontab guru (---> http://crontab.guru/).
First, the executable must be provided as full path in cron.
Example:
7 * * * * /bin/bash /path/to/pinging.sh
Second, create a wrapper script for pinging.sh >> pingdata.log and add that to crontab.
Third, your crontab entry is wrong. There must be 5 fields whereas your's have 4 (maybe that's a typo ?)
I want to add time-lag between same role. e.g. roles :app = [app1, app2, app3]
My expectation(pseudo code):
app1: "1 * * * * rake 'heavy:task'"
app2: "3 * * * * rake 'heavy:task'"
app3: "2 * * * * rake 'heavy:task'"
1,2,3 is not important, but time-lag is important.
How to add time-lag between same role?
My actual schedule.rb:
every :hour, roles: [:app] do
rake 'heavy:task'
end
Actual result(pseudo code):
app1: "0 * * * * rake 'heavy:task'"
app2: "0 * * * * rake 'heavy:task'"
app3: "0 * * * * rake 'heavy:task'"
My stab at this. Sleep randomly for 6 seconds, executed serverside
every :hour, roles: [:app] do
on :all, in: :parallel do
execute 'sleep #{rand(6)}'
rake 'heavy:task'
end
end
I want to run a cron job every hour after a certain start time. Currently my cron job expression is
cronExpression = seconds + " " + minutes + " " + hours +"/1" + " " + " * * ? *" ;
(seconds, minutes, hours are passed in by the user selection)
The job starts at the right time and runs every hour until midnight but then stops until the hour on the next day and then resumes. How do I get the job to continuously run and not stop at midnight?
I understand I can change the expression to
cronExpression = seconds + " " + minutes + " " * * * ? *" ;
but then it will not take into account the start time. It will just run at every hour.
Thanks in advance,
Rich
Do you mean you want the job to start at the given time and then run once hourly forever? If so, I don't think a cron expression is the right approach.
If you're using a scheduler it should be straightforward to start the job and run forever at a given interval. For example, here's a snippet from the Quartz scheduler docs for JobBuilder:
JobDetail job = newJob(MyJob.class)
.withIdentity("myJob")
.build();
Trigger trigger = newTrigger()
.withIdentity(triggerKey("myTrigger", "myTriggerGroup"))
.withSchedule(simpleSchedule()
.withIntervalInHours(1)
.repeatForever())
.startAt(futureDate(10, MINUTES))
.build();
scheduler.scheduleJob(job, trigger);
Run a wrapper every hour which runs your job if the current time is after your start time.
For example,
case $(date +%H) in
09 |1[0-6] ) pingcheck ;;
esac
would run pingcheck (whatever that is :-) between 09:00 and 16:59.
Use your own expression
cronExpression = seconds + " " + minutes + " " * * * ? *" ;
with the startAt(your start time) method() mentioning the start time of the trigger. This start time will implicitely tell the quartz when the trigger will start coming into effect.