I posted a question the other day about setting alternative minutes in cron, and i was given a lovely simple answer.
0-59/2 * * * * first_script
1-59/2 * * * * second_script
This worked brilliantly, however i have seen realized that i need my scripts to run quicker than every minute.
I know cron doesn't support seconds, but you can bluff it by using sleep, like so
* * * * * /foo/bar/your_script
* * * * * sleep 15; /foo/bar/your_script
* * * * * sleep 30; /foo/bar/your_script
* * * * * sleep 45; /foo/bar/your_script
So i need to combine the both of these so that i can get them to run alternatively every 15 seconds for instance.
Any ideas?
Ended up with the following code to get my scripts to run in shorter intervals than 1 minute.
* * * * * /usr/bin/php -q /path/to/file/script1.php
* * * * * sleep 15; /usr/bin/php -q /path/to/file/script2.php
* * * * * sleep 30; /usr/bin/php -q /path/to/file/script1.php
* * * * * sleep 45; /usr/bin/php -q /path/to/file/script2.php
Related
postgres#name-prod-psql-197fb74f68-9psrh:/$ psql "host=name-prod.postgres.database.azure.com port=5432 dbname=prod user=user password=XXX"
psql: error: could not connect to server: Connection timed out
Is the server running on host "name-prod.postgres.database.azure.com" (10.110.0.4) and accepting
TCP/IP connections on port 5432?
If I run traceroute inside the POD
[root#utils /]# traceroute name-prod.postgres.database.azure.com
traceroute to name-prod.postgres.database.azure.com (10.110.0.4), 30 hops max, 60 byte packets
1 10-240-0-226.prometheus-node-exporter.prometheus.svc.cluster.local (10.240.0.226) 0.037 ms 0.019 ms 0.009 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
It used to work for 8 days and then suddenly stopped.
Postgres is placed in subnet 10.110.0.0/16
Aks in prod-private-eks 10.240.0.0/16 with Microsoft.Sql service endpoint added
What could be the issue?
Would suggest you to Open a Firewall Port for PostgreSQL if haven’t
Please refer this document to how to Open a Port in Windows Defender Firewall:
https://manifold.net/doc/mfd9/open_a_firewall_port_for_postgresql.htm
In PostgreSQL’s case it’s typical to use port 5432 if it is available. If it isn’t, most installers will choose the next free port, usually 5433.
Reference: postgresql port confusion 5433 or 5432?
I need to add a new task for crontab which will execute it in a different TZ than the local machine time.
I succeed to do it as you can see in the example below, but the problem is that from time i changed the TZ all the jobs after refers to the new TZ
* * * * * rubHello.sh
0 19 * * * runKuku.sh
CRON_TZ="Europe/Rome"
17 13 * * * /tmp/job1.sh
0 18 * * * /tmp/Job2.sh
in the example above, job1 runs in Europe/Rome as my request, but also job2
runs in that time which is NOT OK.
it there a way to tell crontab change the TZ for only specific task and get back to default crontab TZ for the next jobs after?
Thank you.
Try this (presuming you're in Istanbul), CRON_TZ variable should be set before your cron entry :
* * * * * rubHello.sh
0 19 * * * runKuku.sh
CRON_TZ="Europe/Rome"
17 13 * * * /tmp/job1.sh
CRON_TZ="Europe/Istanbul"
0 18 * * * /tmp/Job2.sh
OR
* * * * * rubHello.sh
0 19 * * * runKuku.sh
0 18 * * * /tmp/Job2.sh
CRON_TZ="Europe/Rome"
17 13 * * * /tmp/job1.sh
This should work, I believe:
* * * * * rubHello.sh
0 19 * * * runKuku.sh
17 13 * * * TZ="Europe/Rome" /tmp/job1.sh
0 18 * * * /tmp/Job2.sh
I am using node-cron. Please help to explain to me the different between:
var pattern_1 = '58 * * * * *';
var pattern_2 = '*/58 * * * * *';
when running this function:
new CronJob(pattern, function() {
console.log('lalalalala')
}, null, true, 'America/Los_Angeles');
As described in cron man page:
Step values can be used in conjunction with ranges. Following a range
with ''/'' specifies skips of the number's value through the
range.
and:
Steps are also permitted after an asterisk, so if you want
to say ''every two hours'', just use ``*/2''.
So:
var pattern_1 = '58 * * * * *';
executes "at 58th seconds of every minute". The second pattern:
var pattern_2 = '*/58 * * * * *';
executes "every 58 seconds".
The first patterns will run your cronjob every 58th second: 00:00:58, 00:01:58, 00:02:58...and so on.
The slash character can be used to identify periodic values. For example */15 * * * * * means, that your job will run ever 15th second: 00:00:15, 00:00:30, 00:00:45 ...and so on.
In my opinion */58 doesn't look very useful. This will execute every 58th second of every minute, so just use the first one.
The second pattern:
var pattern_1 = '58 * * * * *';
It executes at "58th seconds of every minute".
The second pattern:
var pattern_2 = '*/58 * * * * *';
Same as pattern 1 so it also executes at "58th seconds of every minute".
Why it executes the script every 2 minutes?
Shouldn't it execute every 10 minutes ?
*\10 * * * * /usr/bin/python /var/www/py/LSFchecker.py
*\10 * * * *
Should probably be
*/10 * * * *
You can try:
00,10,20,30,40,50 * * * * /usr/bin/python /var/www/py/LSFchecker.py
I need a script in bash to run two applications with different frequency. I'm not that experienced with bash and need some help
I have two programs, m1 and m2, to be run at different rates over time (stress test). m1 is for example run every 10 seconds and m2 every 30 seconds. But it should be possible to change the frequency
To simplify a couple of other answers:
$ while sleep 10; do echo 1; done &
$ while sleep 30; do echo 2; done &
Note that if your "m1" and "m2" commands take time to execute, you won't be running them every 10/30 seconds. The sleep is the delay between the end of one run and the start of the next.
So if you really want to schedule these so they run every 10 or 30 seconds, use cron. Cron runs once per minute, so you need to have multiple cron jobs, offset with sleep:
* * * * * m1
* * * * * sleep 10; m1
* * * * * sleep 20; m1
* * * * * sleep 30; m1
* * * * * sleep 40; m1
* * * * * sleep 50; m1
* * * * * m2
* * * * * sleep 30; m2
Note that if m1 takes more than 10 seconds to run, you'll overlap, which may cause your computer to vanish into a quantum singularity.
$ while true; do sleep 10; echo 1; done &
$ while true; do sleep 30; echo 2; done &
1
1
2
1
1
1
2
...
I think what you are looking for is the sleep command in combination with a while true loop.
while true; do m1;sleep 10;done
while true; do m2; sleep 30;done