how to specify multi time in cron expression - cron

Is it possible to have one cron expression to run at 6am and 7:30pm every day?. I understand the following will will run 6am, 6:30am, 7:00pm and 7:30pm,
0,30 6,19 * * *
How will I schedule 6am and 7:30pm in one cron?

You can put more intelligence into the command that gets run, something like:
0,30 6,19 * * * t=T$(date +%H%M) ; [ ${t} = T0600 -o ${t} = T1930 ] && payload
This will actually run the crontab command four times a day (at 6am, 6:30am, 7pm and 7:30pm) but execute the payload proper only at 6am and 7:30pm as desired.
Some people opt to put this extra intelligence into a script that gets run and simply exits if the time isn't one of the desired ones, but I tend to prefer keeping all scheduling control in the crontab file itself.

Related

Executing multiple scripts via Crontab; Continuously repeats and doesnt stop

I have the following cronjob set to execute daily at a specific time:
MAILTO="email address"
16 * * * python3 /home/cladkins/NBA.py && python3 /home/cladkins/NCAABB.py && python3 /home/cladkins/NCAAFB.py
added this via sudo nano crontab,crontab -e
It is executing almost to well, this is a case of it doesn't know what to do if you don't tell it what to do. My intention is at 1600 UTC everyday to have these scripts run once. Current behavior is that it just keeps looping forever. How can i get it to execute each script only once?
I suggest you use lib like celery to manage and track the execution of your cron jobs easily.
After setting up the celery, you will end up having something like this:
CELERYBEAT_SCHEDULE = {
# Executes every day at 16:00
'my-sample-task': {
'task': 'tasks.task_name',
'schedule': crontab(hour=16, minute=0),
'args': (16, 16),
},
}
Check this link for more details.

Scheduler doesn't work in vTiger

I am an intern on a company in Malta. The company has just made a big change from sugarCRM to vTigerCRM. Now we have a problem with the scheduler. What we want is, when a mail is entered it should automatically get synced with the organisations and contacts (I can link them when I click on the "SCAN NOW" button of the mailconverter). But I want it automatically.
But my cron files are not getting updated.
I installed a cron on the linux server with the code below:
*/15 * * * * sh /vtiger_root/cron/vtigercron.sh >/dev/null 2>&1
I adapt code the PHP_SAPI and I added the permissions on the proper files. But still. (as we speak my schedule task for the mail is at 1)
So every 15 minutes the vtigercron.sh is supposed to run vtigercron.php. But it doesn't happen. When I run vtigercron manually every things works fine. (The scheduler cron states get updated) but not with the cron file on the server.
Can somebody please be my hero?
In our crontab -
(sudo) vim /etc/crontab
I scheduled the job like this:
*/15 * * * * webdaemon /bin/bash /var/www/vtigercrm6/cron/vtigercron.sh
Are you getting any errors in /var/log/syslog or /var/log/messages or whichever system log that your OS uses?
This tutorial actually works: https://www.easycron.com/cron-job-tutorials/how-to-set-up-cron-job-for-vtiger-crm
A simpler way:
In the file vtigercron.php, change the line
if(vtigercron_detect_run_in_cli() || (isset($_SESSION["authenticated_user_id"]) && isset($_SESSION["app_unique_key"]) && $_SESSION["app_unique_key"] == $application_unique_key)){
to
if(vtigercron_detect_run_in_cli() || ($_REQUEST["app_unique_key"] == $application_unique_key) || (isset($_SESSION["authenticated_user_id"]) && isset($_SESSION["app_unique_key"]) && $_SESSION["app_unique_key"] == $application_unique_key)){
and then use
http://www.example.com/vtigercron.php?app_unique_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
as cron job URL.
IMPORTANT NOTICE: You may find your app_unique_key in config.inc.php (look for $application_unique_key in it).
Please replace xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx in the URL above with the 32-chars $application_unique_key you find in config.inc.php, and www.example.com with your vtiger install location.

Run a cron job hourly in a set window

My crontab file looks like this:
00 07-22 * * * /usr/bin/php /ab/c.php
but rather than running from 7am to 10pm, it runs at midnight as well. I want it strictly run every hour between 7 am to 10 pm.
Did you try to remove the leading 0s? They can cause you problems. Try
0 7-22 * * * /usr/bin/php /ab/c.php
Besides the 0s which sound strange to me (I never used them), the rest seems ok. Hope this help.

Creating a Named Cron Job

How do you create a cron job from the command line, so that it shows up with a name in gnome-schedule?
I know how to create a cron job using crontab. However, all my jobs show up with a blank name. I'd like to better document my jobs so I can easily identify them in gnome-schedule, or similar cron wrapper.
Well, just made a cronjob in Scheduler, and took a look at my crontab file, and it looked like this:
0 0 * * * ls >/dev/null 2>&1 # JOB_ID_1
Notice the JOB_ID_1 at the end.
I went into ~/.gnome/gnome-scheduler/, looked at the files there, and there was one named just 1 (as in the number "one") which had a bit of info, including the name
ver=3
title=Hello
desc=
nooutput=1
So, I made a second cronjob:
0 0 * * * ls -al >/dev/null 2>&1 # JOB_ID_2
Copied the file 1 to 2 to match the JOB_ID_2, changed the description, making the file as:
ver=3
title=This is a test
desc=
nooutput=1
Then I switched over to Gnome-Schedule, and it had added the cronjob, and had the name updated.
Follow the same steps, and you should be able to manually name any cronjob you want

best way to reindex sphinx in ubuntu hardy

I'm running a slice of ubuntu hardy.
I've installed sphinx, and I would like to run the sphinx indexer every x minutes.
What is the best way to go about doing this?
The standard Unix approach is cron, so you could for example edit /etc/crontab and add a line like
*/5 * * * * root sphynx [whatever other options you need]
which means
'every five minutes' (for the */5 part)
of every hour (the * in position 2)
of every day of the month (the * in position 3)
of every month (the * in position 4)
of every day of the week (the final * in position 5)
Another example: '4 5 * * 6' amounts to 'at 5:04am (four minutes after five) on every Saturday (day of the week is 6).
You may need to or want to switch the user from root to, say, www-data is sphynx runs as that, and you obviously need to adjust the arguments.
Lastly, look into the directories
$ ls -1d /etc/cron.*
/etc/cron.d
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
for examples --- other packages put their jobs there (and this mechanism is more general, and newer, than direct editing of /etc/crontab.
Here is what I do to reindex and then restart the search daemon once a day.
* * /1 * * root cd /home/sphinx && bin/indexer --all --rotate && bin/searchd --stop && bin/searchd

Resources