Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
Ok, the backup delay is quite large. After several hours, it finally did a backup run....
I try to support shared prefs backup using BackupManagerService. The logs on the devices show that BackupManagerService detects after the app install that no backup exists and schedules the initial backup. However, it does not get executed. How long does it usually take to execute? What strings should I search for in the logs? Can someone please paste a log of a successful backup/initial backup?I triedhttps://github.com/luciofm/BackupManagerTestbut that does not work either. The onCreate method never gets called. Can someone please verify and fix the example?Strangely, it works on an old android-10 Google sdk arm emulator image, but not on the corresponding x86 atom android-19 google sdk image, and not on my real devices (Samsung android-10 galaxy s-plus, samsung galaxy tablet 10.1).
android shared prefs backup: initial backup scheduled but not executed?
It was all to do with unhandled result sets. If your query returns some data that data needs to handled or discarded with a SQLMoreResults.
I'm encountering a "strange" problem and I have no idea of what is happening (I'm new to SQL Server).I'm doing a database backup to a backup device which I created in SQL Server Management Studio. I'm running a simple queryBACKUP DATABASE abc TO abcBackupDeviceand this works fine, but any following SQLExecDirect returns "Invalid cursor state" error.I'm running a C++ app in Visual Studio 2012 and SQL Server 2012 Express as well.Any ideas?
SQL Server Express - invalid cursor state after backup
I'd say that rsync would be quite a good way of doing this you could either backup the entire directory or you can use the "--files-from=" parameter to specify a file containing a list of what you want to backup, aka the htdocs directory and config files.You could have a look at the rsyncexample pagethis covers both local and remote backups.ShareFollowansweredFeb 3, 2009 at 20:56Mark DavidsonMark Davidson5,52355 gold badges3636 silver badges5454 bronze badgesAdd a comment|
I want to both backup my Xampp directory and also transfer it to another computer.Is there an easy way to do this?When I try to copy it, it gives me a restriction, even though I am not running xampp at the time.Thank you!
How do you backup Xampp directory?
SQL Replication, clustering, RAID 5ShareFollowansweredFeb 3, 2009 at 13:46tsilbtsilb8,0171313 gold badges7272 silver badges9999 bronze badges2Thanks tslib. Was kinda hoping for some static files, but I guess most folk work in SQL anyway.–Stu AndrewsFeb 3, 2009 at 21:59Ahh. You still have RAID. My group backs up our physical data/files on an identical server off-site in a failover config.–tsilbFeb 3, 2009 at 22:39Add a comment|
I'm implementing Backup functionality into my new (small) app,Oldaer. I've got standalone desktop files (rather than sitting in a SQL db).Looking around, I decided on using a Clarion 3rd-Party Template that will package them into one file and then compress (huffman's) that one file. Restoring is just the reverse. Uncompress, unpack.However, I'm not convinced this is ideal.What Backup functionality do you implement for your dataset?Of course, there's a lot more in "Backup/Restore" functionality. Location, Tracking/Archiving, Out-of-the-box Information (like better ways of letting the User know what was in the archive file). But that's another question.
What Backup Library/Code Do You Use For Your Dataset (Files On Disk)?
Here is what I do in such a case:Useprocmonto track down registry usage. Have an eye onHKCR\CLSIDandNAME NOT FOUNDresults therein.Take note of the CLSIDs it is not finding, Google them up to get a clue if they might have to do with your problem. Find out which .dll provides them, and register that .dll with regsvr32 (or use the respective installer for the missing component, if a whole bunch of stuff is missing).ShareFollowansweredOct 10, 2008 at 15:33TomalakTomalak335k6767 gold badges541541 silver badges634634 bronze badgesAdd a comment|
I need to do some work with a backup WSS .dat file and I'm having real trouble making it do anything.I've got it installed through stsadm and that appears to have gone smoothly, but the site now redirects me to an error page - just the classic "File Not Found" one, but in the URL it suggests the errortext would be "Class not Registered" if there was a more informative error message.When I run "stsadm -0 enumsites -url=http://my-restored-site/" I get this:C:\>"C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\BIN \stsadm" -o enumsites -url http://my-restored-site <Sites Count="1"> <Site Url="http://my-restored-site" Error="Class not registered" /> </Sites>Is there any way for me to tell what class is not registered or is there something else altogether going on here? I have enabled Sharepoint logging but it appears to have had absolutely no effect, certainly no file exists on the path I have asked it to use.
"Class not Registered" restoring a Sharepoint ( WSS ) 2003 backup.dat file
Azure backup server needs .NET framework 4.6, server should be join to a domain and SQL Server Standard.For more information refer:https://learn.microsoft.com/en-us/azure/backup/backup-azure-microsoft-azure-backupAzure Backup agent needs Microsoft .NET framework 4.5 and windows PowerShellFor more information refer:https://learn.microsoft.com/en-us/azure/backup/backup-configure-vaultShareFollowansweredNov 13, 2017 at 15:59Vikranth SVikranth S48155 silver badges1010 bronze badges1While installing the Azure backup agent on windows server 2008 it also installed Microsoft Virtual server 2005 r2 sp1. Does this affect the working of running server or application on the server?–VshahNov 14, 2017 at 5:02Add a comment|
What are the dependencies of the Azure backup agent, Azure backup server (such as the specific version of ".net framework" and any additional software) Can anyone list out these dependencies I can find it anywhere
Azure MARS agent software dependencies
If you are referring to Azure Backup Agent, the Azure backup agent provides network throttling. Throttling controls how network bandwidth is used during data transfer. This control can be helpful if you need to back up data during work hours but do not want the backup process to interfere with another Internet traffic. Throttling applies to back up and restore activities. For more information refer the section “Enable network throttling”ShareFollowansweredNov 8, 2017 at 18:37Vikranth SVikranth S48155 silver badges1010 bronze badgesAdd a comment|
Hi we are using Microsoft Azure to back up MS SQl DB as well some part of data files. The backups works smooth for an year now. We set up the frequency for these incremental backups as 3 times a day. on normal back up Azure takes a 50 to 80 MB backup and on after each two days it taking 800 MB to 1000 MB as back up also in the first session of the day. This 800 to 1000 MB cause my network overload sometime. So I want to know how can I find why this is happening after each two days and how can I stop this or else how can I shift this abnormal back up ( as per my assumption) to some other timings at night.
MICROSOFT AZURE INCREMENTAL BACKUP
To answer your date part problem: the commanddate /tcan give you the current date. A "shortcut" for that command is the dynamic environment variable%date%(only if you didn't override that variable with some other value). If you combine one of the two with afor fyou can easily extract the year, the month and the day given the format of your date. Before I show you the solution I'll have to warn you:theformatin which thedate /tcommand and the%date%variable return the date depends on your settings(I think location AND/OR language settings, probably depends on windows version). In my case the format wasdd DD/MM/YYYYwith:ddtwo letters of the name of the day of the weekDDthe current day of the month (the 2 digits format)MMthe current month of the year (the 2 digits format)YYYYthe current year (4 digits format)Soon my side, in order to get the day, the month and the year I had to use thefor fon this way: use/and(whitespace) as delimiters and extract the 2nd, 3rd and 4th fields respectively representing the day, the month and the year.@echo off for /f "tokens=2-4 delims=/ " %%G IN ("%date%") DO ( set day=%%G set month=%%H set year=%%I ) echo day: %day% echo month: %month% echo year: %year%ShareFollowansweredFeb 1, 2017 at 11:08J.BaobyJ.Baoby2,19722 gold badges1212 silver badges1717 bronze badgesAdd a comment|
I am trying to make a backup script using cmd. This is my code so far:X: MKDIR "2017MMDD XXX Restore Profile" CD "X:\2017MMDD XXX Restore Profile" MKDIR "Desktop" MKDIR "Favorites" MKDIR "My Documents" MKDIR "Pictures" MKDIR "Videos" XCOPY "C:\Users\%username%\Desktop" "X:\2017MMDD XXX Restore Profile\Desktop" XCOPY "C:\Users\%username%\Favorites" "X:\2017MMDD XXX Restore Profile\Favorites" XCOPY "C:\Users\%username%\Documents" "X:\2017MMDD XXX Restore Profile\My Documents" XCOPY "C:\Users\%username%\Pictures" "X:\2017MMDD XXX Restore Profile\Pictures" XCOPY "C:\Users\%username%\Videoes" "X:\2017MMDD XXX Restore Profile\Videos" PauseThe problem is that it only copies the files and not the folder (If there are any). I need a function that will copy both files and folders.BONUS, is there any command for cmd to write the date? (Instead of 2017MMDD, where you need to fill out the rest) :)
backup folders using cmd
Not an Azure user myself, but I guess you could try mounting your Azure file share using webdav (on windows you can try thisguide, on linux you can mount using davfs2, there are plenty of guides out there). After that, change the NVR recording path to your webdav share and you should be all set.Take into account, thought, that this will be really sub-optimal, for at least 2 reasons:1) In case your internet connection goes down, you'll be losing recording footage.2) Writing real-time data to a remote share (especially mounted using webdav) is never a good idea. Carefully take into account latency and throughput. Preferably do some tests first.A better option would be to record locally and schedule a task (or cron job, if you're on linux) to move the files offsite every night/month/whatever, and only after successful completion remove it off the local disk.ShareFollowansweredSep 25, 2015 at 17:33nitefoodnitefood1Add a comment|
We have an UVC camera from Ubiquiti and I'd like to upload the surveillance footage to Azure cloud, I don't want to do a daily backup of the footage, I need the footage to be uploaded directly to Azure somehow. Can I do this?
Video camera to upload footage to Azure
that's actually Powershell and not VB script. You need to run the code inside Powershell for this to work.This link looks pretty good for a brief introduction if you haven't done PS before.http://www.abstrys.com/files/BeginningPowershellScripting.htmlShareFollowansweredDec 12, 2012 at 16:23user303754user30375445933 silver badges1212 bronze badges1I think you kindly for that answer, I am absolutely swamped at work and I had no time to suddenly learn scripting just for this, I think I can figure it out from here, I just needed a kick in the right direction.–SaskBerryDec 12, 2012 at 19:57Add a comment|
I got this script off the technet website, but I get an error when I try to execute it on my Windows 7 machine. I am completely new to scripting, but I wonder if this was made for an older OS and needs a bit of changing for Windows 7? I'm quite sure the guy who wrote it up tested it.I get the Windows Script Host Error as follows: Line: 1 Char: 10 Error: Expected Identifier Code: 800A03F2 Source: Microsoft VBScript compilation error.Here's the script:Function New-BackUpFolder($destinationFolder) { $dte = get-date $dte = $dte.tostring() -replace "[:\s/]", "." $backUpPath = "$destinationFolder" + $dte $null = New-Item -path $backUpPath -itemType directory New-Backup $dataFolder $backUpPath $backUpInterval } #end New-BackUpFolder Function New-Backup($dataFolder,$backUpPath,$backUpInterval) { "backing up $dataFolder... check $backUppath for your files" Get-Childitem -path $dataFolder -recurse | Where-Object { $_.LastWriteTime -ge (get-date).addDays(-$backUpInterval) } | Foreach-Object { copy-item -path $_.FullName -destination $backUpPath -force } } #end New-BackUp # *** entry point to script *** $backUpInterval = 1 $dataFolder = "C:\fso" $destinationFolder = "C:\BU\" New-BackupFolder $destinationFolder
Expected Identifier Code Error when running script?
check the minute your at now and add them as a list to your crontrigger. if you start the trigger at minute 12 for example add0 2,12,22,32,42,52 * * * ?as your cron expressionEdit:Another solution would be to define a simpletrigger that repeats every ten minutesSimpleTrigger trigger = new SimpleTrigger("myTrigger", null, new Date(), null, SimpleTrigger.REPEAT_INDEFINITELY, 10L * 60L * 1000L);ShareFolloweditedAug 9, 2010 at 10:21answeredAug 9, 2010 at 8:48Nikolaus GradwohlNikolaus Gradwohl19.9k33 gold badges4747 silver badges6262 bronze badges3Thanks that would work, but thats not very smart, is not it. I am working on huge application which onstartup will require the CronJob to be started. I dont want to change the cron expression every time i am going to start my application. Do we have some alter solution please?–Sandeep JindalAug 9, 2010 at 10:171i fear that the smarter version is not configurable through spring.–Sandeep JindalAug 15, 2010 at 13:311you can add @PostContruct before your method, so after your bean is initialized, it runs for the first time.–hiwayMar 10, 2014 at 3:31Add a comment|
I am using Quartz Scheduler using Spring. I want to configure the same with following schedule:Run Job Every 10 minutes starting NOWI am using following expression for the same.0 */10 * * * ?I thought * in the minutes field would make it run the first minute, but it does not do that way. It runs the first 10th minutes from now and then every 10 minutes afterwards. Can anybody please suggest me the reason for this behavior and the solution to my problem also?
Quartz Cron Expression: Run Job Every 10 minutes starting NOW (immediately)
You just need to think of cronjob as running a shell command at a specified time or day.So your first job is to work out how to run your shell command.psql --host host.example.com --port 12345 --dbname nameofdatabase --username postgres < my.sqlYou can then just add this to your crontab (I recommend you usecrontab -eto avoid breaking things)# runs your command at 00:00 every day # # min hour wday month mday command-to-run 0 0 * * * psql --host host.example.com --port 12345 --dbname nameofdatabase < my.sqlShareFolloweditedDec 28, 2020 at 7:10Ajay Takur6,19055 gold badges4141 silver badges5656 bronze badgesansweredOct 18, 2011 at 10:11Matthew RudyMatthew Rudy16.8k33 gold badges4646 silver badges4444 bronze badgesAdd a comment|
I assume that all I need to do is to:Create an sql file e.g. nameofsqlfile.sql contents:perform proc_my_sql_funtion();Execute this as a cron job.However, I don't know the commands that I'd need to write to get this cron job executed as a postgres function for a specified host,port,database, user & his password...?
How do I create a cron job to run an postgres SQL function?
We do a lot of background processing for django using Celeryhttp://celeryproject.org/. It requires some effort to set up and there is a bit of a learning curve, but once it's up and running it's just awesome.ShareFollowansweredNov 16, 2011 at 18:12Dmitry B.Dmitry B.9,20733 gold badges4747 silver badges6565 bronze badges62Same here. RabbitMQ + Celery + django-celery.–JordanNov 16, 2011 at 18:15In your experience, is Celery a little bit of overkill for simple messaging queues in Django? I've look into it before and although it runs well, I thought it was way to much for my particular use case. Do you agree or am I overlooking something? Any downside to using a daemons at OP suggested above?–ChrisCMay 23, 2013 at 11:04depending on the definition of "simple messaging queues" - yes ;)–Dmitry B.May 23, 2013 at 17:011a scheduled job is not the same as a daemon process.–AlexSep 22, 2016 at 20:02@lxer, And if you read beyond the question's title, you realize that the OP wasn't really asking about daemon processes, but for a better replacement for this cron setup. Context is important when providing an answer that will be useful to the person who asked it.–Dmitry B.Sep 22, 2016 at 20:09|Show1more comment
In my Django project I have to do repeatedly some processing in the background. This processing needs access to Django stuff, so I put it into Django's commands and run it as cronjob. Right now I realize, that I have to do some of them more frequently (cronjob has limitation to invoke command at most every 1 minute). Another problem is that I don't have enough control, to protect running the same command in one time. It's happen when one processing takes longer than one minute. I think that I should run them like daemons, but I am looking for pure way to do it with Django. Have you ever faced with this problem or know any clean solution for it?
How to run own daemon processes with Django?
Usehttps://console.cron-job.org/and setup an HTTP call after every 14 minute.ShareFollowansweredMar 9, 2023 at 4:08MehtaMehta24711 gold badge33 silver badges1313 bronze badges22thanks, I actually fixed this by using node-cron on the server itself and self-pinging every 10 minutes, turned out pretty well and my server hasn't slept since then. I'll keep this site in mind tho, whenever I wouldn't want to write my own cron jobs :)–Vic TørMar 13, 2023 at 8:57I won't advise pinging the server every 10 minutes. You'll run out of free hours on your free plan in a few days.–OdunsiJan 25 at 14:16Add a comment|
I got a node app hosted on a render server, and as it's under the free tier, it sleeps after 15m of inactivity, and I wrote a cron job using the node-cron package. if the app is asleep, the node-cron functions won't be active. is there any way to keep my render app awake?I've used Heroku and Kaffeine (for keeping heroku apps awake)are there any alternatives for Render?
prevent render server from sleeping
Crontab with -e option does open your default editor with the current cron file and installs it after exiting.First of all, save your actual cron file to be sure of not losing or breaking anything.crontab -l > backup.cronYou can directly install a file that you have cooked:crontab yourFile.textOr use a pipe in a script:#/bin/bash Variable="your scheduled tasks" echo $Variable | crontabYou will get the error messages in the case of bad formatting.More info:man crontabShareFolloweditedAug 15, 2015 at 22:55answeredJul 21, 2015 at 21:11blashserblashser98166 silver badges1414 bronze badges2Keep in mind that this will delete any previous crontab there was before, check it withcrontab -lbefore–golimarAug 13, 2015 at 16:09@golimar yes, all protection is good when you touch this kind of configuration files. I update my answer with your suggestion.–blashserAug 15, 2015 at 22:51Add a comment|
Let's say I write cron files via script and modify them direct under/var/spool/cron/crontabs/. When using the commandcrontab -ecrontab checks the syntax when I exit the editor. Is there any way to do the same check via script?
How to check cron syntax by script like "crontab -e" does?
Here was the issues:Error showed up: TypeError:init() takes exactly 2 argumentdocumentaton:https://pypi.python.org/pypi/python-crontabhelped to resolve the issue.Reason: 1 - crontab was installed not python-crontabHere's the completed code:def main(): from crontab import CronTab cron = CronTab(user=True) job = cron.new(command='python /opt/my_script.py') job.minute.on(2) job.hour.on(12) cron.write() if __name__ == "__main__": main()ShareFollowansweredJul 16, 2015 at 6:34LacerLacer5,8161010 gold badges3434 silver badges4646 bronze badges1This was my exact problem. Un-installing crontab then installing python-crontab fixed my issue.–twegnerApr 11, 2018 at 4:03Add a comment|
I'm fairly new to python and I'm trying to create a cronjob through a python script but I keep getting an error. Any help would be greatly appreciated it to show me what I'm doing wrong?thankspython scriptfrom crontab import CronTab cron = CronTab(user=True) job = cron.new(command='python /Users/<useraccount>/Desktop/my_script.py') job.minute.on(2) job.hour.on(12) cron.write()Errors:Traceback (most recent call last): File "/Users/<useraccount>/Desktop/01-python-crontab.py", line 3, in <module> cron = CronTab(user=True) TypeError: __init__() got an unexpected keyword argument 'user'
python - crontab to run a script
I'm not a fan of editing the crontab or per-user cron jobs; anyone editing thecrontabcan mess up your deployment. Instead, I create scripts that go into/etc/cron.$intervalwhich allows me to deploy them withPuppet(see thecron type) or a simplecpcommand.So if I need a script that runs once per day, I either put that into$project/cron/cron.daily/$projectif I install without Puppet.Alternatively, if you really need to merge crontabs, you should add a header and footer to each script, so it's easy to see where some part of the crontab comes from. The header/footer also allows you do automatically add/remove each script.You should never replace the whole crontab because one day, someone will manually edit it. The edit will work until you deploy again at which time it will suddenly fail silently.ShareFolloweditedMar 30, 2020 at 3:59thiagobraga1,53922 gold badges1616 silver badges3030 bronze badgesansweredSep 20, 2012 at 12:38Aaron DigullaAaron Digulla325k109109 gold badges611611 silver badges828828 bronze badgesAdd a comment|
Closed. This question isopinion-based. It is not currently accepting answers.Want to improve this question?Update the question so it can be answered with facts and citations byediting this post.Closed4 months ago.Improve this questionI have a bunch of projects that I push to a server with git and fab. They're a load of Django sites. Some of these sites have cron jobs.I would like to be in a situation where I can:Manage the site's cron jobs by editing a file locally and running a fab command (egfab save deployas I currently do)Have new jobs get installed remotely (only) and replace any old jobs (I don't want clone jobs each time)Keep the same highly customisable time settings. Not all my issues can be solved by @hourly.What's the best way to approach this?I am aware ofHow do you deploy cron jobs to production?but the focus there seems to be about hacking the cronning into the fabric script and (at least in the answers) there's no consideration that there might be more than one project that needs cron jobs per user.I'm after something that is stored in the VCS (I don't push my fabfile to git - and it's shared between all my projects) that will work alongside other jobs in crontab. It's no good if ProjectA and ProjectB overwrite each other's jobs each time I deploy.
How can I version control my projects' cron jobs? [closed]
There is a few node packages to management and persist scheduled jobs:Agenda(mongodb persistence)Bree(Redis persistence)Bull(Redis persistence)nodejs-persistable-scheduler(MySql persistence)ShareFolloweditedJul 23, 2021 at 18:47answeredApr 21, 2017 at 20:02J.C. GrasJ.C. Gras5,16411 gold badge4040 silver badges4545 bronze badgesAdd a comment|
I have my app innode jsand i want them to be executed on its scheduled timeBut the problem is in between thatif my server crash/stop/restart then those scheduled jobs are not persisted and are not executed.Also, all my jobs are scheduled and executed using only single process, but i want multiple process to do the job.I want all my jobs to bepersisted and executed even if my node server restartedor better its get executed even if my server is not running.Agenda- using mongoDB, which i don't want to use.Node-scheduler - not able to persist cron jobsvar ctab = require('crontab'); ctab.load(function(err, crontab) { var job = crontab.create('* * * * * *'); var jobs = crontab.jobs(); crontab.save(function(err, crontab) { }); });
Persist my cron jobs and execute them even if my node server restarted
This looks like a cron job rescheduling initiated by hosting provider to evenly distribute server loads throughput (I am thinking of hosting service because you mentioned cpanel). You should contact your hosting support to discuss it.ShareFollowansweredJan 3, 2014 at 11:18pmodpmod10.7k11 gold badge3737 silver badges5353 bronze badges13As per my understanding you are using shared server where you can't set cron time less than 15 minutes otherwise it will change.–Anand MishraFeb 12, 2014 at 15:30Add a comment|
I have a cron job*/2 * * * *in the cpanel , after several hours this changes automatically to*/17 * * * *, or*/19 * * * *or*/15 * * * *. I noticed this change many days. I was waiting for the task to complete in 2 minutes, several tasks have been completed, but after several hours i saw it isn't working, so I checked the cron jobs in cpanel and I saw the*/2was changed to*/19 * * * *.It's not a good for every one because its not possible for check cron jobs every day.
Cron job schedule time changes automatically
You can try out different timing values in the crontab sandbox. It will show you a list of run times. www.dataphyx.com/cronsandbox/.ShareFolloweditedApr 26, 2013 at 6:11answeredFeb 14, 2013 at 7:16mlbx02mlbx024922 bronze badgesAdd a comment|
I don't know how to set up cron with ssh? I opened ssh and typed "crontab -e". What do I do then? I want to repeat the function every minute. I have this code as "cron command to run": php -f /var/www/vhosts/nf-test-host.tk/httpdocs/admin/cron/cron.php.I am on CentOS. What should I do, exactly? Thanks in advance!
How to set up cron job on CentOS
As a general rule, you're going to want to save a setting to indicate that a job is running. Similar to how "Spring Batch" does the trick, you might want to create a table in your database simply for storing a job execution. You can choose to implement this however you'd like, but ultimately, your scheduled tasks should check the database to see if an identical task is already running, and if not, proceed with the task execution. Once the task has completed, update the database appropriately so that a future execution will be able to proceed.ShareFollowansweredOct 29, 2013 at 16:32MattSenterMattSenter3,0901919 silver badges1818 bronze badgesAdd a comment|
We have a Spring + JPA web application. We use two tomcat servers that run both application and uses the same DB.One of our application requirmemnt is to preform cron \ scheduled tasks.After a short research we found that spring framework delivers a very straight forward solution to cron jobs, (Annotation based solution)However since both tomcats running the same webapp - if we will use this spring's solution we will create a very problematic scenario where 2 crons are running at the same time (each on a different tomcat)Is there any way to solve this issue? maybe this alternative is not good for our purpose?thanks!
Scheduled tasks with multiple servers - single point of responsibility
+25As clearly stated in thedocumentation for @Schedule and @Schedules, you need to have two @Schedule annotations if you run two schedules - even if you don't like that fact.Due to the cron-like limitations of having ranges only within individual elements (hours, minutes, seconds...), it's simply not posible to give that additional information of skipping the last two executions at *:50 and *:55 only at 5pm.That said, you'd probably end up with something like@Schedules({ @Schedule(hour="10-16" minute="*/5"), @Schedule(hour="17" minute="0,5,10,15,20,25,30,35,40,45") })As you end up with schedule information into you sourcecode that way (even if it's in the form of an annotation) you could just as well run every five minutes and immediately return from the method if called after 5:49pmShareFollowansweredApr 26, 2017 at 10:31JanJan13.8k33 gold badges3131 silver badges5656 bronze badgesAdd a comment|
I'm required to have a schedule that runs every 5 minutes from 10 am to 5:45pm, how do I do this with the @Schedule annotation?So far, I'm limited to the @Schedule(hour=10-18;minute=*/5), but they insist I should have it until 5:45pm not 6pm.
Java EE6 Schedule Range
Yes - your intuition is correct. This is essentially what the database people would call amaterialized view. For example, to give an achievement for post count > 30, do something like this:posts { id, user_id, content } users { user_id, post_count, has_thirty_posts }When a post is inserted into thepoststable, add 1 topost_countin theuserstable. Ifpost_count > 30, sethas_thirty_posts = true.There are other ways to store the schema. This is just a gross simplification, but it should give you the idea. This is also calledDenormalization(i.e. storing redundant data).ShareFollowansweredMar 3, 2011 at 2:06jterracejterrace65.9k2222 gold badges161161 silver badges203203 bronze badgesAdd a comment|
I've been looking at an open source clone of SO,http://github.com/cnprog/CNPROGI don't know Python/Django but I can still read whats going on,The developers, seem to only be awarding badges with cron jobs, The awards are given out by the methods, being the "Rules" of the Criteria that must be met to achieve the award.inthisfile, which is the Criteria,YetIn the answer tobest-way-to-store-badge-criteriaits saying not run a query like,"select count(*) from posts where user = :user"// for every post.Which is kind of like the CNPROG method, but to insteadhave a simple rule that watches each post come by, and "count them", storing the rules state in the user profile.So by the words "counting them", does that mean it would be better to record everything in one table like,class UserStats int voteUpCount int voteDownCount int score int commentCount int viewCount int offensiveFlagCount int imageCount int feedbackCount int commentEditCount int commentDeleteCount int questionCount int questionEditCount int questionDeleteCountThen with this data make rules from it, with a simpleif(commentCount > 10)...upon every comment that the users posts, then preform the SQL queryQIf someone could further explain the answer from the questionbest-way-to-store-badge-criteria, But give an example with a "rule", "criteria" and database designThese would be used with some "per user action" and cron jobs to give badges
Badge achievement system like SO: Data being used + Criteria(instant awarding & cron jobs)
Not sure if you are still looking for a solution but I came across this :https://github.com/agenda/agendaIts a lightweight node.js scheduling library.ShareFollowansweredApr 14, 2018 at 15:03codeinprogresscodeinprogress3,34188 gold badges4848 silver badges7373 bronze badges1The agenda seems to be using cronJobs under the hood–daRulaSep 21, 2023 at 8:21Add a comment|
I am building a SaaS application, where users logs in and creates reminders for a particular date and timein future, and when the time is met, my application is responsible for reminding the respective user about the reminder he/she has set in thepastExample:Say user"Foo"logs in and creates a reminder on 2:30pm 27th April 2018 (a date time in future).My application should send an email on that exact date-time to"Foo"as any other reminder app.Like this there can be thousands of reminders ACTIVE for hundreds of users.TechnologyNode.jsWhat I triedI have tried packages likenode-scheduleand other cron-job solutions but I believe/found - Cron-jobs are not designed for solving problems like one of mine.Please help me with a solution. Thanks
Node.js, date-time based reminder
I tried your script and command line, and it is working on my machine. Are you sure your script is located at/home/loop.py?Also, don't expect to see those prints, because you are specifying the-b(background) option, so the process is being detached from your terminal. Try running it without the-bfor testing purposes and then you can redirect the standard output to a logfile with the-stdoutoption:sudo /sbin/start-stop-daemon --start --pidfile /home/loop.pid \ --user www-data --group www-data -b --make-pidfile --chuid www-data \ --exec /usr/bin/python /home/loop.py --verbose -stdout /var/log/loop.logShareFolloweditedDec 20, 2011 at 16:47answeredDec 20, 2011 at 16:42ChewieChewie7,11555 gold badges3030 silver badges3636 bronze badges2it start works for me to after reboot, i don't know why) I have ubuntu 11.10 and it seem where is no stdout option in this version of start-stop-daemon. I saw intresting option " -R|--retry <schedule> check whether processes die, and retry." For ex if i kill my script it will start it again? but i can't understand how to use this option in my example?–evgDec 20, 2011 at 19:28Odd, but you're right. Then you'll have to write yourself to stdout from the python script:import sys; sys.stdout.write(STRING).–ChewieDec 20, 2011 at 20:32Add a comment|
I'm trying to start python script with start-stop-daemon:sudo /sbin/start-stop-daemon --start --pidfile /home/loop.pid \ --user www-data --group www-data -b --make-pidfile --chuid www-data \ --exec /usr/bin/python /home/loop.py --verbosebut no python script in my processes. What i do wrong?loop.py:import time while True: print "working..." time.sleep(3)
start-stop-daemon and python
try0 0 * * 0/2,1/20and1are Sunday and Monday, and/2is 'every other'EDIT:After more research into cron, the above is incorrect because/2indicates the step (every other value), so0/2is equivalent to0,2,4,6, and0/2,1/2is equivalent to0,1,2,3,4,5,6,7which explains why you saw it interpreted as every single day of the week.In your example above1/14means starting with 1st of the month, increment by 14, yielding1,15,29That being said, if this were for a *nix crontab, then you could've been more granular about the schedule by having something like0 0 * * Sun,Mon check_if_should_run.sh && the_script_to_run.sh. Using Ncrontab, I can't think of a way to set up every-other-week scenario.ShareFolloweditedMar 14, 2012 at 18:29answeredMar 13, 2012 at 20:11AlexAlex10.8k88 gold badges4141 silver badges6363 bronze badges11I've tried it and i got recurrence of every day, starting from Sunday. If i try 0 0 * * 0/2 , it gives me a recurrence of every Sunday and every two days–Eddie RozenblatMar 14, 2012 at 8:00Add a comment|
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed12 years ago.Improve this questionI want to create a cron job that runs every x weeks and on a specific weekdays. for example: run every 2 weeks on midnight every Sunday and Monday.the cron expression is stored for every "plan" and i usencrontabfunction in SQL Server 2008 to generate the dates of given cron expression.Is there an expression for it? or even join of several expressions?I've tried to use the following expression, but it always gives the the same days in months0 0 1/14 * * 2012-01-01 00:00:00.000 2012-01-15 00:00:00.000 2012-01-29 00:00:00.000 2012-02-01 00:00:00.000 2012-02-15 00:00:00.000 2012-02-29 00:00:00.000EDIT:I was looking for a recurrence of every x days/weeks and the main problem with cron, is that it resets the recurrence to the first day of month every time. for example, if i start the recurrence on 29th for every 3 days, the next occurrence will be the 1st day of next month.I've neglected cron for the next solution:http://www.codeproject.com/Articles/20343/Recurring-Date-Generator-with-Pattern-Coding
Cron job run every x weeks and on specific days [closed]
I found a solution by following this :Spring @Scheduled annotationand this :http://tutorials.jenkov.com/java-util-concurrent/scheduledexecutorservice.htmlShareFolloweditedMay 23, 2017 at 11:47CommunityBot111 silver badgeansweredAug 19, 2015 at 11:52Alexis B.Alexis B.16611 gold badge11 silver badge1010 bronze badges29Can you please explain how did you find solution, some sample code.–changemeOct 27, 2016 at 10:25Sorry for that long time reply. I do not have any access to the code anymore. I'll post a code sample if/as soon as I can.–Alexis B.Aug 21, 2017 at 14:08Add a comment|
I'm using Spring scheduling to have batches in my application.@Scheduled(cron = "${batch.name|0 0 21 * * ?}") public void restart() { }Values are load from a properties file and default value from the @Scheduled annotation parameter.Now, I would like to be able to load a cron value from database (so from an object) without using Quartz library, only with the default Spring scheduler.Does someone know if and how it is possible?Thank you in advance.
How to load a cron expression from db and reschedule it with Spring?
System -> Scheduled Cron JobsClick Create a new scheduled cron job.In Command box enter /usr/bin/php -q /var/www/path/to/your_php_script.phpClick "Times and dates selected below .." radio buttonClick "Selected.." under Minutes sectionSelect 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 (use control key) and click 'Save' button.ShareFolloweditedFeb 5, 2015 at 7:40Amit Bera7,59177 gold badges3232 silver badges5757 bronze badgesansweredMay 31, 2012 at 14:40Naresh Kumar NakkaNaresh Kumar Nakka50044 silver badges1010 bronze badges11-q mean supress HTTP header or CGI mode only,php.net/manual/en/features.commandline.options.php–fedmichJan 20, 2015 at 12:43Add a comment|
I am trying to setup a Cron job using Webmin to run every 5 min. It needs to target a .php file and run the php script in that file. When I enter the path to the file in the "Command" field, it doesn't work. I am just wondering what I am doing wrong, and where do I put the file path that I need the Cron job to run.Thanks!
Setting up a cron job with Webmin
It's because the service name on 16.04 iscron, notcrond. So your command should be:sudo service cron startYou can verify on your server by looking in the/etc/init.dfolder. All the services are there.ls -l /etc/init.dShareFolloweditedDec 3, 2017 at 23:43Benjamin W.48.6k1919 gold badges117117 silver badges122122 bronze badgesansweredApr 6, 2017 at 15:49VilmosVilmos53644 silver badges88 bronze badges3YES, I realize that. Thanks. Just now, the cron try to execute the command and don't show any error despise not really execute. In the status is showed: Abr 06 12:18:01 h-lcee CRON[14155]: (h) CMD (python '/home/h/Documents/UNICAMP/Scripts Python/bandecoWarning.py') Abr 06 12:18:01 h-lcee CRON[14154]: pam_unix(cron:session): session closed for user h–hildogjrApr 6, 2017 at 17:13If the command shows that it executed in the cron.log file then the command was run. Cron will only tell you it did or didn't run the command. It doesn't capture the result. You will need to look at the script you have written to make sure there are no error in it that would cause it to be exiting. Check your /var/log/syslog file at the time the command ran to check for errors. That may have some information to help you troubleshoot.–VilmosApr 6, 2017 at 20:00Notsystemdnow, instead ofinit.d?–geotheoryApr 7, 2018 at 21:23Add a comment|
I am programming some schedule task in my Ubuntu 16.04.But when I try to start the crond.service bysudo service crond startI receive the messagecrond.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)What's the problem? The tasks was added to the schedule by crontab command and look fine (the command works in the terminal, have the correct tree folder, I just added the day-hours parameters).
Start crond.service on Ubuntu 16.04
If you have control over the cron or command, have you considered passing a command-line argument, and reading it with$_SERVER['argv'][0]?* * * * * /usr/bin/php /path/to/script --cronIn the script:<?php if(isset($_SERVER['argv'][0]) and $_SERVER['argv'][0] == '--cron') $I_AM_CRON = true; else $I_AM_CRON = false;ShareFollowansweredDec 6, 2009 at 4:05gahooagahooa134k1212 gold badges9999 silver badges102102 bronze badges11Worked for me, although in my case I had to use$_SERVER['argv'][1]:)–bbeckfordJan 22, 2014 at 11:01Add a comment|
I need to determine whether the PHP file is being loaded via cron or command line within the code. How can I do this?
How to determine if a PHP file is loaded via cron/command line
ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState | head -1Tested and works on 10.7.*, foundhere.Update 2019-02-26:Still works on macOS 10.14.3 MojaveShareFolloweditedFeb 26, 2019 at 10:53Jørgen R10.7k77 gold badges4343 silver badges6161 bronze badgesansweredApr 7, 2013 at 22:45SaucierSaucier4,27011 gold badge2525 silver badges4747 bronze badges94Nomeans open,Yesmeans closed–Brian LowJun 27, 2017 at 4:241Also works on macos 10.14! I'm checking for closed state with that:ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState | head -1 | grep YesIf i printed some text - the lid is closed. And vice versa.–De_VanoNov 8, 2018 at 0:231Also works on macos 10.15!–William GustafsonNov 15, 2019 at 17:211-d 1is enough. (-d: Limit tree traversal to the specified depth.)–RockalliteDec 31, 2020 at 2:47Also works on 10.15.7!–SaharshFeb 9, 2021 at 16:03|Show4more comments
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed10 years ago.Improve this questionI'm running OS X 10.8 (Mountain Lion). I was wondering if there was a terminal command to check if the macbook pro's lid is currently closed. If I used grep, what would I be looking for exactly, and where?The reason I ask is because I have cron jobs scheduled to run every 30 minutes. However, crontab doesn't run when the computer is sleeping/hibernating. My solution was to use pmset to schedule wakes every 30 minutes. However, I need a way to put my computer back to sleep on the condition that the lid is currently closed. I don't want my computer to be awake for too long with the lid closed i.e. awake all night when I'm sleeping because that could damage the screen.
How to Check if Macbook Lid is closed via Terminal? [closed]
Solution:apt-get --purge remove sendmail-base sendmail-cf sendmail-docThis just popped up for me too. I thought that I had removed sendmail when I installed Postfix but these cron jobs started popping up. Removing the sendmail file from /etc/cron.d worked until I restarted the machine, at which point it was regenerated. Removing the packages listed solved the problem once and for all. :-)ShareFollowansweredNov 7, 2012 at 19:00jrn75jrn7533622 silver badges44 bronze badges1I did exactly as you did. Initially, I only removed the cron entry and when restarted the emails came back flooding my inbox. Only after removing the entire sendemail packages, the emails stopped. Thanks for sharing the solution.–Pothi KalimuthuDec 9, 2012 at 1:56Add a comment|
I'm a fool in linux. So i tried to set up some things on my root. Well and after time a suspicious cron job started to bomb me. i get about 1 email every 10 minutes saying:Cron test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp/usr/share/sendmail/sendmail: line 880: /usr/sbin/sendmail-msp: No such file or directoryDoes someone know what this could be?The email is adressed to "[email protected]"....greetings
Strange emails from Cronjob. (No such file or directory)
I recently began using Amazon's linux distro on ec2 instances and after trying all kinds of things for cron all I needed was:sudo service crond startcrontab -eThis allowed me to set a cron job as "ec2-user" without specifying the user. For example:0 12 * * * python3 example.pyIn fact, specifying a user here prevented it from running. I also posted thishere.ShareFolloweditedMay 23, 2017 at 11:45CommunityBot111 silver badgeansweredFeb 1, 2017 at 10:13j3pyj3py1,1591010 silver badges2222 bronze badgesAdd a comment|
I have an Amazon EC2 instance running my website. I need to setup a Cron Job to run my file every 12 hours.if file setup via command line so please give a detail step wise.Does anyone have any advise?
How to cron job setup in Amazon ec2
Use this:10 * * * * {CMD}which means start new job at 10 minutes of every hour: 1:10, 2:10, ...If you want to start at 1:10, 2:20, 3:30, ..., then you will need to write a lot of manual rules, each starting at those times (or write your own scheduler).ShareFollowansweredJan 7, 2013 at 7:04mvpmvp113k1414 gold badges126126 silver badges151151 bronze badges0Add a comment|
I did the following:0 */10 * * * {CMD}but it worked until midnight and didn't continue the next day. Can someone please suggest something?
How to run cron job every one hour and 10 min
As phantom is probably installed in/usr/local/bin, you should add that dir toPATHin your crontab. The following should do the trick:SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binShareFollowansweredJun 14, 2014 at 12:16Artjom B.Artjom B.61.5k2424 gold badges129129 silver badges226226 bronze badges0Add a comment|
I'm running a python script through a cronjob. I have a virtual environment and in the cronjob I'm running it through this virtual environment. When I run the script normally phantomJS starts as it should, but running it through a script in a cronjob I get this error. What is missing in the cronjob to be able to start phantomjs?Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen Traceback (most recent call last): File "/home/scraper/superfish-extension/chrome_3day.py", line 96, in <module> main() File "/home/scraper/superfish-extension/chrome_3day.py", line 73, in main browser = use_phantomjs() File "/home/scraper/superfish-extension/chrome.py", line 81, in use_phantomjs browser = webdriver.PhantomJS() File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 50, in __init__ self.service.start() File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/selenium/webdriver/phantomjs/service.py", line 69, in start raise WebDriverException("Unable to start phantomjs with ghostdriver.", e) WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen
Starting phantomJS from a script in a cronjob
Try it with$()instead of backticks. And you probably do need to escape the percent signs sincecronconverts them to newlines otherwise.* 0 * * * /usr/bin/mysqldump -uUser -pPass Db_name > /var/www/db_backup/db.$(date +\%Y\%m\%d\%H\%M).sqlAlso, you shouldstore the password in an option filewith secure permissions (eg. 600 or 640) instead of passing it on the command line.ShareFollowansweredAug 9, 2010 at 22:47Dennis WilliamsonDennis Williamson353k9292 gold badges376376 silver badges441441 bronze badges1Thank you! That is just what I was looking for. And thanks for the tip about the option file as well.–amac44Aug 11, 2010 at 15:57Add a comment|
The following works fine from command line/usr/bin/mysqldump -uUser -pPass Db_name > /var/www/db_backup/db.`date +%Y%m%d%H%M`.sqlbut when I try to do that in cron, I get the error:bad ` sign errors in crontab file, can't installI saw someone else on the net solve the same problem by escaping the percent signs, but that didn't help and I tried it with just date inside backquotes with no format specifiers and still got the errors.I've also seen date's argument enclosed in single or double quotes, but that doesn't help either.Granted I could just throw it into a script and execute that I suppose - but what fun is that?Any ideas? I'm using RHEL 5.
Cron error with using backquotes
I would use30 * * * *to run a command half past every hour.It is worth remembering that in crontab you define a pattern to match the current time against and not an exact time. Every minute crond will awaken and match the current time against your pattern and if there is a match, run your command.ShareFolloweditedJul 5, 2010 at 20:39answeredJul 5, 2010 at 20:26MartinMartin5,17733 gold badges1818 silver badges1616 bronze badges4So should 60 * * * * be used to run a job hourly?–Mr MorganJul 5, 2010 at 20:30Not exactly. You would use 59 * * * * * to run a job at the last minute of every hour. I highly recommend taking a look at man 5 crontab.–MartinJul 5, 2010 at 20:32Using Chron as implemented in Quartz in Java on Windows.–Mr MorganJul 5, 2010 at 20:43And here I thought you were talking about cron on Unix :) Quartz looks like it could be use full, thanks for mentioning it.–MartinJul 5, 2010 at 20:55Add a comment|
Can anyone suggest a way to set a Cron trigger to run at half past the hour every hour?So far, I've got one working hourly as per "0 0/60 * * * ?".Am I looking at "0 0/30 * * * ?" at all?Mr Morgan.
Cron trigger to run at half past the hour every hour
This part just puts the output into oblivion so you'll never see it:>> /dev/null 2>&1Why not try:* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txtAnd check to see if the cron is run in/my_path/example.txtThe default inspire command essentially just echo's a quote so the only way to see it in a cron is to output it to a file on the server.You can do this using something similar to this:$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);Further details:https://laravel.com/docs/5.4/scheduling#task-outputShareFolloweditedFeb 27, 2017 at 11:14answeredFeb 27, 2017 at 11:01RhuRhu2,08911 gold badge1212 silver badges1111 bronze badges2tried this one. example.txt contains: Running scheduled command: '/usr/bin/php' 'artisan' inspire > '/dev/null' 2>&1–prgrmFeb 27, 2017 at 11:071This show's it is working correctly, next you can try outputing it to a specific file:laravel.com/docs/5.4/scheduling#task-outputusing $schedule->command('inspire')->everyMinute()->appendOutputTo($filePath); or something similar.–RhuFeb 27, 2017 at 11:11Add a comment|
I am trying to set up scheduler in Laravel.Here is my crontab which I debugged and works fine - atleast with my cron job* * * * * /bin/echo "foobar" >> /my_path/example.txtI don't know if this one works:* * * * * php /var/www/myproject/artisan schedule:run 1>> /dev/null 2>&1Here is my schedule function in Kernel:protected function schedule(Schedule $schedule) { $schedule->command('inspire') ->everyMinute(); }When I am in my project and tryphp artisan inspireit actually works, so I expected it to fire every minute, but it won't do anything. Nothing happens.Any ideas?
Laravel + Crontab not working
Since Ansible 2.0 you have thecronvarcommand:# modify /etc/cron.d/sweep_for_rebel_code - cronvar: name: MAILTO value:[email protected]cron_file: sweep_for_rebel_codeSee the official documentation athttps://docs.ansible.com/ansible/latest/modules/cronvar_module.htmlShareFolloweditedAug 25, 2020 at 13:02Stijn Diependaele57844 silver badges1313 bronze badgesansweredFeb 10, 2017 at 14:46chiborgchiborg27.5k1414 gold badges9898 silver badges118118 bronze badges15If you want to setMAILTOto""to disable emails, you should usevalue: "\"\"", or else will you will get the ansible errorFAILED! => {"changed": false, "msg": "\"/tmp/crontabPbSYxL\":0: bad minute\nerrors in crontab file, can't install.\n"}(tested on ansible 2.4).–deterralbaFeb 6, 2018 at 8:48Add a comment|
I'm using Ansible to create a cron.d file using the cron_file parameter.But how can I add a MAILTO to the file?It seems the env=true is only for crontab, not cron.d files. Am I wrong?
How to add MAILTO to a cron.d cron_file in Ansible?
cron: - description: do something url: /myscript schedule: every 1 hours from 00:10 to 23:10FromGoogle App Engine Documentation:By default, an interval schedule starts the next interval after the last job has completed. If a from...to clause is specified, however, the jobs are scheduled at regular intervals independent of when the last job completedSo, it will run at 00:10,01:10.... etcShareFollowansweredDec 26, 2013 at 4:36nizznizz1,13377 silver badges1616 bronze badges1Amazing solution. Thanks!–oaviFeb 2, 2022 at 15:10Add a comment|
In Google App Engine, I'd like to schedule a task every hour at 10 minute. I mean, at 00:10, 01:10, 02:10, ... 22:10 and 23:10 every day: every o'clock + ten minutes. Crontab equivalent will be like10 * * * * mytaskWhat should I write in mycron.yaml?cron: - description: do something url: /myscript schedule: (?)P.S. Season's greetings, everyone!
cron.yaml in Google App Engine: how to schedule task every hour at specific minute?
Bear in mind that running PHP from the shell is completely different from running it in a web server environment. If you haven't done command-line programming before, you may run into some surprises.That said, the usual way to pass information into a command is by putting it on the command line. If you do this:php /my/directory/file.php "some value" "some other value"Then inside your script,$argv[1]will be set to"some value"and$argv[2]will be set to"some other value". ($argv[0]will be set to"/my/directory/file.php").ShareFollowansweredApr 22, 2012 at 0:49Mark ReedMark Reed93.5k1717 gold badges140140 silver badges181181 bronze badges2I tried that, it didn't work. do I have to put the second argument between quotations so I can read it there? because I didn't use quotations in the command.–Hesham SaeedApr 22, 2012 at 1:00Is your PHP built for the command-line? It's a different SAPI, and requires a different PHP binary from the one you use for CGIs.–Mark ReedApr 22, 2012 at 1:11Add a comment|
I have created a crontab rule:* * * * * php /my/directory/file.phpI want to pass a variable to be used in the file.php from this crontab.What is the best method to do this?
pass crontab a variable and read it from PHP?
"Is there a way for me to just have crontab run a script as if I ran it myself from my terminal?"Yes:bash -li -c /path/to/scriptFrom the man page:[vindaloo:pgl]:~/p/test $ man bash | grep -A2 -m1 -- -i -i If the -i option is present, the shell is interactive. -l Make bash act as if it had been invoked as a login shell (see INVOCATION below).ShareFollowansweredAug 12, 2009 at 15:24pglpgl7,70122 gold badges2424 silver badges3131 bronze badges1Great answer, this is the appropriate way to execute things from a crontab when desiring an environment identical to executing it from a command-line.–Mahmoud AbdelkaderJun 18, 2010 at 4:10Add a comment|
This keeps happening to me all the time: 1) I write a script(ruby, shell, etc). 2) run it, it works. 3) put it in crontab so it runs in a few minutes so I know it runs from there. 4) It doesnt, no error trace, back to step 2 or 3 a 1000 times.When I ruby script fails in crontab, I can't really know why it fails cause when I pipe output like this:ruby script.rb >& /path/to/outputI sorta get the output of the script, but I don't get any of the errors from it and I don't get the errors coming from bash (like if ruby is not found or file isn't there)I have no idea what environmental variables are set and whether or not it's a problem. Turns out that to run a ruby script from crontab you have to export a ton of environment variables.Is there a way for me to just have crontab run a script as ifI ran it myself from my terminal?When debugging, I have to reset the timer and go back to waiting. Very time consuming.How to test things in crontab better or avoid these problems?
How to test things in crontab
You should be using>>for redirection to append to the file, rather than>which overwrites the log each time the script runs.*/1 * * * * /usr/bin/php /path/to/CRON.php >> /path/to/log/CRON_LOG.txt 2> /dev/null ##---------------------------------------^^^^^^There really isn't any need to dofopen()/fwrite()inside the script itself, since the cron job is already handling the output redirection.ShareFollowansweredFeb 26, 2012 at 19:35Michael BerkowskiMichael Berkowski269k4646 gold badges445445 silver badges391391 bronze badges0Add a comment|
cron line look's like:*/1 * * * * /usr/bin/php /path/to/CRON.php > /path/to/log/CRON_LOG.txt 2> /dev/nullCRON.php<?php require_once 'config.php'; define('CRON', dirname(dirname(__FILE__))); $parts = explode("/",__FILE__); $ThisFile = $parts[count($parts) - 1]; chdir(substr(__FILE__,0,(strlen(__FILE__) - strlen($ThisFile)))); unset($parts); unset($ThisFile); $CRON_OUTPUT = "STARTING CRON @ ".date("m-d-Y H:i:s")."\r\n"; $CRON_OUTPUT .= CleanLog() . "\r\n"; $CRON_OUTPUT .= "\r\n"; echo $CRON_OUTPUT; $fh = fopen(''.CRON.'/log/CRON_LOG.txt', 'a'); fwrite($fh, $CRON_OUTPUT); fclose($fh); die(); ?>CleanLog function:global $db; $resp = ''; $db->query('SQL'); $resp = 'Deleted '.$db->rows_affected.' entries from table'; return $resp;In file only these two lines showing and function by the time as i can see executed two times:CRON_LOG.txtSTARTING CRON @ 02-26-2012 21:26:01 Deleted 0 entries from table STARTING CRON @ 02-26-2012 21:26:01 Deleted 0 entries from tableWhat's wrong with it, why it only produce those lines and file doesn't updated (in file only date/time changing, nothing more, it should add more lines and even file size should grow up) ?
crontab php file and output to log file result
In your crontab put this:*/3 * * * * /home/ubuntu/my_script.sh >> /home/ubuntu/Logs.txtIt will redirect stdout to this file.You might also want to have stderr redirected (exceptions etc.), so:*/3 * * * * /home/ubuntu/my_script.sh >> /home/ubuntu/Logs.txt 2>> /home/ubuntu/errors.txtOr you can have them all in one file:*/3 * * * * /home/ubuntu/my_script.sh >> /home/ubuntu/Logs.txt 2>&1ShareFollowansweredJul 25, 2014 at 14:16ElmoVanKielmoElmoVanKielmo11k22 gold badges3232 silver badges4949 bronze badges31None of those schedules on cron worked for me. Somehow python seems to be hiding the output, because this works with a simple "echo" or "ping" command.–Vini.g.ferJul 25, 2014 at 16:[email protected] seems like a permissions problem. Are you running this cronjob asubuntuuser or more importantly as the same user as from command line?–ElmoVanKielmoJul 28, 2014 at 8:501Same user as the command line, which is ubuntu user. I call cron like this: sudo crontab -e -u ubuntu–Vini.g.ferJul 28, 2014 at 10:34Add a comment|
This question already has answers here:Correct way to write line to file?(17 answers)Closed9 years ago.I'm starting a python script using cron, like this:#Python script called every 3 minutes in case script crashes */3 * * * * /home/ubuntu/python_script.sh &And my script has several prints for debugging. I want to print those messages into a file, for example /home/ubuntu/Logs.txtMy script also check if the python call is already running so it won't start it again:#!/bin/bash lines=$(ps -ef | grep python_script.py | wc -l) if [ $lines -ne 2 ]; then python python_script.py & fiHow do I print my messages to this file? I'm using python 2.7Update: Edited my code with the following:1) Added this as the first line of my python script:from __future__ import print_function2) Opened the log file after the last import, and right after that added a test print:log = open("/home/ubuntu/Logs.txt", "w+") print("Testing...", file = log)If I simple run it from the terminal, it prints to the file fine. But if I schedule it with cron it doesn't write to the file.Update 2: Ended up stumbling on a solution with "logger" command. On my shell script I had to add "2>&1" (in the shell script, not crontab as described by ElmoVanKielmo) and " | logger &". Final solution looks like this:#!/bin/bash lines=$(ps -ef | grep python_script.py | wc -l) if [ $lines -ne 2 ]; then python python_script.py 2>&1 | logger & fiand it outputs any prints to /var/log/syslog file, which is good enough for me.
Start python script with cron and output print to a file [duplicate]
I have tested this and the following expression works fine"0 0 0 1,15 * ?"the 1,15 statement fires triggers on 1st and 15th of every month at 00:00 hours. You can change the first three zeroes to fire them at a particular time you want.the 1st zero -> secondsthe 2nd zero -> minutesthe 3rd zero -> hoursShareFollowansweredMar 25, 2014 at 12:17Pratik RoyPratik Roy72411 gold badge55 silver badges2121 bronze badges271st - min, 2nd - hour, 3rd - dom,4th - mon,5th - dow–karthik vMar 22, 2018 at 7:59is "quartz" different than standard linux cron (as described by karthik v)?–moodboomNov 14, 2021 at 23:32Add a comment|
I want to set the scheduler with a quartz cron expression which will trigger every 15 days ,for example 1st and 15th of every month.The 0 15 10 15 * ? is triggering only on 15th of every month.
Quartz Cron expression :Run every 15 days ie twice in a month
WTF?! A double-embedded variable is the problem, it turns out. Why is this? You can test with the below cron script:tmpdir="/tmp" subdir="$tmpdir/subdir" */1 * * * * root echo $tmpdir $subdir >/tmp/cron.outThe resulting file:/tmp $tmpdir/subdirShareFollowansweredOct 24, 2013 at 21:04CaptSaltyJackCaptSaltyJack15.6k1717 gold badges7171 silver badges100100 bronze badgesAdd a comment|
This file below is in /etc/cron.d. Ubuntu 12.04 Server BTW.zurmo_install_path="/var/www/zurmo" zurmo_commands_path="$zurmo_install_path/app/protected/commands" */1 * * * * www-data cd /var/www/zurmo/app/protected/commands && ./zurmoc jobManager super EmailArchiving >/dev/null 2>&1 */1 * * * * www-data cd "$zurmo_commands_path" && ./zurmoc jobManager super ProcessOutboundEmail >/dev/null 2>&1The first item fires off fine, the second does not. Once I change the second line to use the literal path and not the variable, it fires off fine. Yet when I write my own test cron job to use variables, they work ok. This is a real stumper!
cron script variable expansion not so good?
We are warned when we open the console of our application by ssh:Note: Any data outside '/ home' is not persistedTherefore, a possible solution in this case is to launch a script at the start of the application, so that after each restart the cron service is installed and the work necessary to execute the Laravel scheduller tasks is created. I'll explain what has worked for me for my PHP + Laravel application hosted on Azure Linux Webapp:1.Create the start script /home/startup.sh:apt-get update -qq && apt-get install cron -yqq (crontab -l 2>/dev/null; echo "* * * * * /usr/local/bin/php /home/site/wwwroot/MyAppFolder/artisan schedule:run >> /home/cronresult.txt 2>&1")|crontab service cron startNote: note that we are indicating that our PHP PATH is in the /usr/local/bin/php directory. We will have the output of the command in a file /home/cronresult.txt, which will help us in debugging any problem from its execution.2.Set ‘/home/startup.sh’ as ‘startup command’ in our azure panel, as indicated by @HeyMan in his answer.3.We will have to restart our application for the startup script to load.ShareFollowansweredDec 3, 2021 at 12:41jssDevjssDev96388 silver badges2020 bronze badges1this is working i checked–HasithaAug 22, 2023 at 8:39Add a comment|
Crontab command not found on Linux web app on azure,I'm trying to schedule a cronjob for a laravel application.I'm trying to run a cronjob for my laravel web app.The solutions online suggest that I use webjobs for this, in my case it is blurred out, the reason for this I was told by the technician that it is because it's a Linux web app, I then have to run cronjobs using crontab. which I did, but once in a while I get "-bash crontab: command not found" which suggest that the whole configuration gets lost somehow.
How to run cronjobs on an azure linux hosted webapp?
FromAskUbuntu question:There is no log file by default - the output goes to stdout.In order to have a log specify it with the-loption i.e.-l clamav.logShareFolloweditedApr 13, 2017 at 12:22CommunityBot111 silver badgeansweredMay 19, 2015 at 19:34Neil SmithlineNeil Smithline1,55699 silver badges2121 bronze badgesAdd a comment|
I use this code to run a daily check through cron30 01 * * * /usr/bin/freshclam --quiet; /usr/bin/clamscan --recursive --no-summary --infected / 2>/dev/nullI'm not sure if this code stores a log file at all.I want to know: If it does, then where can I find it? If it doesn't what is required to be changed to store the logs?
Where is my ClamAV log?
I've done this a number of ways and there are a bunch of ways to do it. I think the current best practice is to useResqueto queue the jobs andRescue Schedulerto schedule them.Resque is a solid 'job scheduling' app that can handle all kinds of tasks for you. Resque Scheduler can be fed full cron expressions (in addition to other methods of scheduling tasks) to manage the jobs.One of the advantages of this approach is that you get theResque Webapp that gives you a web app to use for monitoring the jobs (or launching them for one-off job runs).I've used this approach with Heroku and it works well and has been reliable.ShareFolloweditedMay 7, 2012 at 0:09answeredMay 7, 2012 at 0:03Kevin BedellKevin Bedell13.4k1010 gold badges7979 silver badges115115 bronze badgesAdd a comment|
I'm working on the billing system for my app, but I'm not sure how to go about setting up scripts that run daily, one to send out payment reminders (email), and another to downgrade subscriptions that have not been renewed.Any tips on how to do this?Any gotchas I need to watch out for?Any gems that I might be able to use?I've completed most of the purchasing side already, so am not looking for gems like paypal_recurring, or stripe - just need to handle the payment reminders and dealing of accounts that have expired.
How to run daily tasks/scripts in a Rails project?
On some distributions you can:* 19-23,0-5 * * *Check here:https://unix.stackexchange.com/questions/67158/crontab-entry-with-hour-range-going-over-midnightShareFolloweditedApr 13, 2017 at 12:36CommunityBot111 silver badgeansweredOct 14, 2015 at 21:25Paul CarltonPaul Carlton2,88522 gold badges2727 silver badges4848 bronze badgesAdd a comment|
How can I create a cron job that runs from 19:00 to 5:00? This doesn't work:* 19-05 * * ....Should I use two jobs? 👇* 19-23 * * .... * 1-5 * * ....
How to run cron job before midnight to after midnight (over midnight)?
Yes, it will.You should make your program create a .pid file (for example in /var/run/). When it starts, it should check if such file already exists and if so exit.Which program/script are you running?ShareFollowansweredMay 28, 2009 at 18:33MartinodFMartinodF8,22722 gold badges3232 silver badges2828 bronze badges2I am running a php script to send mail.–Tony BorfMay 28, 2009 at 20:33Something like this will do the trick thendreamincode.net/code/snippet2407.htm–MartinodFMay 29, 2009 at 2:32Add a comment|
If I have a cron job that run every 10 minutes and for some reason this one time it takes 12 minutes to run the job, will cron start another instance of my code while the previous one is still running? if so how can you prevent this on linux?
Running a Cron Job
UNIX Cron expressions and Quartz ones are differents. Simply,In Unix(minute, hour, day, month, day_of_week, year)In Quartz(second, minute, hour, day, month, day_of_week, year)You can usethisto know if a Cron expression is correct.EDIT : Look atCronExpression.ValidateExpressionmethod.ShareFolloweditedOct 10, 2014 at 7:08answeredOct 9, 2014 at 20:27KraissKraiss95977 silver badges2323 bronze badges22which function on the API page you linked can I use to say if my cron is correct?–disasterkidOct 10, 2014 at 6:46Just to add to this answer, we can use CronExpression.IsValidExpression(string expression) if you're looking to make decisions based off of that call.–Nabakamal DasSep 6, 2023 at 12:56Add a comment|
I would like to have user-defined cron expressions in my program. Are there are validators for cron expressions so that the user cannot insert an invalid cron code?N.B.I think the cron expression on Quartz.Net has a slight different format than the one used in UNIX. I would like to the Quartz version of it.
Cron expression validator
Is it possible to write some service in XAMP server to run the script daily at scheduled time?Create aCron Job.ShareFollowansweredNov 9, 2012 at 18:12Jason McCrearyJason McCreary72.3k2323 gold badges136136 silver badges175175 bronze badgesAdd a comment|
This question already has answers here:Closed11 years ago.Possible Duplicate:How to run a php script in cronI need to run a php script at the scheduled time daily to update some fields in database and to send automated email. How I can do this?Is it possible to write some service in XAMP server to run the script daily at scheduled time? I have no idea how to update database and send email automatically at the scheduled time. Can any one share some ideas or concepts?I am using PHP and MySQL running in Linux Server.
How to run a php script automatically daily? [duplicate]
A cron job won't be able to access cookies, since by definition it is not being invoked from a web browser request. Only the web browser stores a cookie, which contains the session id. No web browser, no cookie, no session.Having said that, if youdoknow the session id somehow, you should be able to start the session manually by feeding the id intosession_id()before usingsession_start().ShareFollowansweredNov 9, 2009 at 6:57deceze♦deceze516k8686 gold badges758758 silver badges904904 bronze badges2And that is only if the session still exists. A cron job running, say, hour or days later will probably try to load a session that doesn't exists anymore.–Carlos LimaNov 9, 2009 at 7:08Thanks a lot for your nice Answer. I like it.–Saiful IslamDec 18, 2017 at 16:12Add a comment|
i am new to cron jobs and i have done much searching on this topic but i couldn't understand it fully. can cron jobs access cookies or session variables?thanks!
can php cron jobs access session variables/cookies?
Yes, you can.Here's a line from mycrontabfile. (You can edit it by runningcrontab -e)*/10 * * * * /var/www/vendor/wp-cli/wp-cli/bin/wp --path=/var/www/ update-creditsThis runs my WP-CLI commandupdate-creditsevery 10 minutes.NOTE: I'm using WP-CLI as a Composer dependency in that website. The path to yourwpbinary may vary.ShareFollowansweredAug 23, 2017 at 15:44Shawn HShawn H57066 silver badges1515 bronze badges11Using full path towpbinary file is the key. It works in my case. Using onlywpwill fail.–Anh TranFeb 29 at 4:40Add a comment|
Is it possbile to run WP cli commands with a cron job? Because I'm setting up a demo site, and want the site to be reset every 12 hour. And i thought that with wp cli, i can reset the installation. Import a file with the right content and so on.Or do you guys have any better idea how to do this?
Run wp cli commands with cron job
You should probably usecronif two conditions are met;It is available on all platforms your code needs to run on.Starting a script on a set time is sufficient for your needs.Mirroring these are two reasons to build your own solution:Your program needs to be portable across many operating systems, including those that don't havecronavailable. (like ms-windows)You need to schedule things in a way other than on a set start time. E.g. on a set interval, or if some other condition it met.ShareFollowansweredApr 16, 2016 at 10:14Roland SmithRoland Smith42.9k33 gold badges6666 silver badges9797 bronze badges0Add a comment|
If you want to run your python script, let's say every day at 6 pm, is it better to go with a crontab entry or with a Advanced Python Scheduler solution regarding to power, memory, cpu ... consumption?In my eyes doing a crone job is therefore better, because I do not see the advantage of permanently running an Advanced Python Scheduler.
Cron job vs Advanced Python Scheduler
First weekday of the month rules:If today is a Monday, then the job should be run if today is also the 1st, 2nd, or 3rd of the monthIf today is a Tuesday, Wednesday, Thursday, or Friday, then the job should be run if today is also the 1st of the monthThe following cron expressions should do the job:H 7 1-3 * 1 H 7 1 * 2 H 7 1 * 3 H 7 1 * 4 H 7 1 * 5 # Would last have run at Wednesday, July 1, 2015 7:00:02 AM EEST; would next run at Monday, August 3, 2015 7:00:02 AM EEST.Beware, because ofthisarticle, youcan'tjust use:H 7 1-3 * 1 H 7 1 * 2-5The above doesn't work! Instead, the job is run on every weekday, twice on the 1st of the month, and maybe twice on the 2nd and 3rd of the month!But I was not able to reproduce it.ShareFolloweditedJul 1, 2015 at 21:23answeredJul 1, 2015 at 20:54Vitalii ElenhauptVitalii Elenhaupt7,22633 gold badges2727 silver badges4444 bronze badgesAdd a comment|
My goal is to trigger a report every first weekday of the month at 7AM (7/1/15,8/3/15,9/1/15, etc.)I am using the following cron expression:H 7 1-3/3 * 1-5It runs on July 1, but it is not scheduled next to run on August 3, but on September 1. How can I get it to run on the first weekday of every month?I am using the following help guide:MINUTEMinutes within the hour (0–59)HOURThe hour of the day (0–23)DOMThe day of the month (1–31)MONTHThe month (1–12)DOWThe day of the week (0–7) where 0 and 7 are Sunday.To specify multiple values for one field, the following operators are available. In the order of precedence,The * specifies all valid valuesM-N specifies a range of valuesM-N/X or */X steps by intervals of X through the specified range or whole valid rangeA,B,...,Z enumerates multiple valuesTo allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible.
Can I get a Jenkins trigger to run every first week day of every month?
This should do it:find /path/to/dir -maxdepth 0 -ctime +1 -exec rm -fr {} +But be careful, and test it first outside ofcron, without the-execpart, so you don't delete something else by accident.ShareFolloweditedMar 14, 2014 at 7:27answeredMar 14, 2014 at 7:18janosjanos123k3030 gold badges233233 silver badges241241 bronze badges12What would I modify to change the amount of days? The+1part? Also this is running on a webserver.–Joe ScottoMar 14, 2014 at 7:19I am using cpanel, for the directory would it be somthing likepublic_html/website/uploads?–Joe ScottoMar 14, 2014 at 7:21@KronoFiles that really depends on your hosting provider. If a command has output in cron, then cron usually emails the output to use. You can runfind public_html/websitewithout any other arguments to print all the files and subdirectories in there and it should get emailed to you. Based on that output you can figure out the right path to use.–janosMar 14, 2014 at 7:25Would I fill my directory in in both/path/to/dir?–Joe ScottoMar 14, 2014 at 7:26Is there any website where I could learn more about this? I'm really interested now.–Joe ScottoMar 14, 2014 at 7:29|Show7more comments
I want to delete a folder and its contents on my host if it is over a day old. The issue is that I have no experience on how to do this with a linux cron job. I should also say that i have looked at google and nothing comes up. I think this is a pretty simple question so please, help me out. Thanks
How to delete folders that are older than a day? (Cron Job)
You can set your system's time zone to the intended time zone and then state the time for that zone in the cron job:sudo timedatectl set-timezone America/New_Yorkand confirm typingtimedatectl, or dosudo dpkg-reconfigure tzdataAfter changing the time zone, make sure to restart cron:sudo service cron restartCron job:30 5 * * * echo "run at half past 5" >> ~/logfile.log 2>&1ShareFolloweditedMar 25, 2021 at 12:55answeredMar 25, 2021 at 12:45rndmGuyrndmGuy16877 bronze badges11I did set the timezone but did not restart the cron, and sure enough the job didn't run at the time I was expecting. Thank you @rndmGuy for the point about restarting cron.–nandanSep 11, 2021 at 8:23Add a comment|
Cron by default uses UTC time zone. How to set it up to use Local time (say CST) in the cron expression (for cron schedule).
How to setup to use local time in cron schedule?
The short answer is: no, you cannot create oneCronJobYML with several crontab times schedules.The easy solution would be to use separateCronJobresource for each crontab line from your example. You can use the same image for each of yourCronJobs.ShareFollowansweredDec 3, 2020 at 10:06Wytrzymały WiktorWytrzymały Wiktor12.5k55 gold badges2929 silver badges4242 bronze badgesAdd a comment|
I want to run one cron at different times.Is it possible to do something like this in my YML file:apiVersion: batch/v1beta1 kind: CronJob metadata: name: my-cronjob spec: schedule: - "*/10 00-08 * * *" - "*/5 09-18 * * *" - "*/10 19-23 * * *" concurrencyPolicy: Forbid ...or do I have to create separate YML files for every schedule time?
Kubernetes CronJob multiple schedule times
You will need a valid DISPLAY and XAUTHORITY to use X-Programms in Cron!To set DISPLAY is very easy, type in the Bash:export DISPLAY=":0.0"In order to get a valid XAUTHORITY you have to look for it. Under Debian/Gnome/gdm3 they are saved in var/run/gdm3/*/database I used the following script:export DISPLAY=":0.0" [ -z $USER ] && USER=$( who | awk '{ print $1 }' | sort | uniq >/tmp/test ) for I in /var/run/gdm3/*; do AUTHUSER="`echo $I | awk -F '-' '{ print $3 }'`" for J in $USER; do [ "${AUTHUSER}" = "${J}" ] || continue USER="$J" export XAUTHORITY="${I}/database" && break done done sudo -u ${USER} /Path/to/xProgrammThe Var $USER can be empty, than the script looks for a valid user, otherwise you can tell the script the var!ShareFollowansweredJul 3, 2012 at 11:00Michèle S.Michèle S.30411 gold badge44 silver badges88 bronze badges2thanks for this excellent answer. I was able to make it work for Ubuntu 20.04 with some minor modification.–Abrar HossainSep 16, 2020 at 11:15What were those minor modifications?–Chris StenkampNov 26, 2021 at 16:47Add a comment|
I want to set up a cron job to run a python script, but it gives me this error:RuntimeError: could not open displayThis is because I import a module that requires me to open display (pylab, for example). Even though my script does not generates any pictures to display on the monitor.Is there any way to let crontab run my jobs with display open (just as if Issh -Xinto a machine)? I don't actually need to generate any graphs to the monitor. I just need to import my modules correctly.
Cron job: how to run a script that requires to open display?
I think there are two things you could do:(1) Run the command from the rake task:task :do_that => :environment do system "do_this" ... endAnd simplify your schedule.rb file to:every 24.hours do rake "do_that" end(2) Run everything from the command line:every 24.hours do command "do_this && rake do_that" endShareFollowansweredMay 9, 2011 at 20:50Pan ThomakosPan Thomakos34.2k99 gold badges8888 silver badges8585 bronze badges0Add a comment|
i'm using whenever to schedule tasks for a rails application.I have a task like:every 24.hours do command "do_this" rake "do_that" endmy point is, when i write it to my crontab, with whenever -w, i see that it generates two independent tasks running at the same time. the problem is, both are logically a sequence, that means, the rake task, "do_that", should run just if the command "do_this" did already, successfully run.I tried to contact both like command "do_this" && rake "do_that" but i received a syntax error.Does exist any trick to create this dependence between tasks in whenever?Does the crontab execute the jobs at same time, in parallel or it process N tasks scheduled at the same time in a queue?
scheduling sequential tasks with whenever gem
You need to output Moodle cron run to the logfile, e.g. your cron.d record may look like:* * * * * www-data /usr/bin/php /var/www/moodle/admin/cli/cron.php >> /var/log/vle/moodle-cron.log 2>&1Then, the content of/var/log/vle/moodle-cron.logwill tell you immediately if cron running fine. If you want to go further, you can even monitor the file for the last update using some monoring tools and get alerts if cron has stopped.ShareFollowansweredSep 22, 2014 at 16:04Ruslan KabalinRuslan Kabalin6,72822 gold badges2929 silver badges2020 bronze badgesAdd a comment|
I've just sended a messege to the server admin asking if he can set the cronjobs on the server and he asked me to tell him if everything is working right. How can I test whether the cronjobs are working or not?
How can I tell if moodle cron is working?
From what I can tell, you may need to either:Set the display variable (Note that it might not be 0, could be 1 or even 2):export DISPLAY=:0Launch a dbus-session:dbus-launchSet the dbus variable:export $(dbus-launch)In your case with a Cron job you can set environment variables like this:env VARIABLE=VALUE <command>So for option 1 your job would look like this:* 9-17 * * 1-5 env DISPLAY=:0 vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1For option 2 you can separate the two commands using &&, like this:* 9-17 * * 1-5 dbus-launch && vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1Something similar for option 3:* 9-17 * * 1-5 export $(dbus-launch) &&vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1ShareFolloweditedJul 24, 2023 at 12:58answeredJun 26, 2020 at 19:12BaaBaa48833 gold badges88 silver badges2323 bronze badges21Note that this spawns two instances of dbus and the first one will not be used. The step 2. should already look like the 3. -export $(dbus-launch)–WereiiJul 24, 2023 at 11:44@Wereii Sorry these should not have been written as steps, 1, 2, and 3 are three individual solutions.–BaaJul 24, 2023 at 12:57Add a comment|
I like to run a cron that snapshots a cam like this:* 9-17 * * 1-5 vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1But when the cron runs it just throws an error I don't understand:** Message: Failed to get session bus: Error spawning command line 'dbus-launch --autolaunch=55644972b3c91c1d24d83d8252721f00 --binary-syntax --close-stderr': Child process exited with code 1In the web I find no clean or good documentation what that is. Can you help me figure it out?
Error in spawning a dbus-launch - what is that?
I faced the same issue but I had edited the crontab file several times before pressing crontab -r, so I could find the previous versions in tmp directory. So try your luck looking into your tmp directory once.ShareFollowansweredSep 28, 2019 at 0:41Darshana BoradeDarshana Borade2111 bronze badgeAdd a comment|
I have deleted mycrontabusingcrontab -rcommand (randeare so close on keyboard and there wasn't question sort ofAre you sure? [Y/n].Its funny, you must use-ioption to enable this question - should be enabled by default :-)Mycrontabrecords are definitely lost or there is some backup file, how can I recover it ?Thank you.
How recover deleted crontab (-r option)
'*/1 * * * *': async() => { console.log("I am running " + new Date(), Object.keys(strapi.config)); await strapi.services.article.publish(); }Inyour-project/config/functions/cron.js. you can add as many functions in the above format. The function name in itself is a cron expression which is parsed by strapi to execute at frequent intervals. There are many online tools that will tell you the cron expression that you want to create.The above function runs every 1 minute, by which I am publishing a content type by using strapi.services. i.e. in file your-project/api/article/services/Article.js I have written a service layer method that at the moment is publishing an article.Similarly, you can send an email from your email content type or any utility file that you have made to trigger an email. For accessing strapi config use:strapi.configobject instead ofstrapi.servicesShareFollowansweredMay 17, 2019 at 17:54Baldeep Singh KwatraBaldeep Singh Kwatra1,1741111 silver badges2020 bronze badgesAdd a comment|
Hi I was wondering If anyone got examples of using Cron Schedule functions on Strapi:https://strapi.io/documentation/3.x.x/configurations/configurations.html#functionslike sending email, accessing the strapi config, etc.
CRON Example for Strapi
It will run at first visit right after the scheduled time.1.- yes, run automatically, but triggered by a visitor.2.- it's enough to sending email in a scheduled basis.For a real cron behavior you can run a script usingcrontabcrontab -e wget -q http://domain.com/wp-content/some-path/your-script.php-q: quiet (no output). Just run the script. Otherwise you will have a lot of files in your server (wget pull files)Tip:http://www.thegeekstuff.com/2011/07/php-cron-job/Using cpanel:http://wiki.hostbillapp.com/index.php?title=Settings:_cPanel:_Cron_jobShareFolloweditedApr 25, 2013 at 19:55answeredOct 15, 2012 at 14:11Igor ParraIgor Parra10.3k1010 gold badges7070 silver badges102102 bronze badges6is this possible to trigger automatically at scheduled time? not depends on visitor–softsdevOct 15, 2012 at 14:22Yes, see my updated answer. I have done it many times for scraping jobs!–Igor ParraOct 15, 2012 at 14:28Can you please tell me where should i have to run/write this script?–softsdevOct 15, 2012 at 14:39Wherever you want in your public website. It is equal to any other php filehttp://domain.com/wp-content/some-path/your-script.php–Igor ParraOct 15, 2012 at 14:42I already scheduled event using Cpanel Cron I'm checking is there to directly using Code Actually I create one plugin in wordpress so this Plugin may be use at different site that's why I am searching solution on that–softsdevOct 15, 2012 at 15:07|Show1more comment
I need details about wp-cron. I usedwp_schedule_eventfor automatically sending emails.Butwp_schedule_eventis only triggered when a user visits our site. How to make the cron run automatically?
When does wp-cron.php run in Wordpress?
You need a blank line between the message header and the body.{ echo "Subject: $SUBJECT" echo "$(< sendmail_list.txt)" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo "Content-Disposition: inline" echo "" cat $CONTENT } | /usr/sbin/sendmail -tA couple of other things:you don't need a subshell here, so I changed the surrounding parentheses to bracessince this is bash, there's a shorthand for$(cat file)--$(< file)ShareFollowansweredMay 19, 2014 at 12:47glenn jackmanglenn jackman243k4040 gold badges224224 silver badges355355 bronze badges3Thanks for response.. I used blank line as told by you. but still it is not able to send mail. seems like some environment setups issues while running the jobs through cronjob...but not able to identify the solution.–KnowledgeSeeekerMay 20, 2014 at 6:48Did you do anything with fedorqui's comment?–glenn jackmanMay 21, 2014 at 10:47Ohh..I just noticed Farmer's comment and don't know how missed fedoqui's....Such a fool I am...Its working now...Thanks everyone..really appreciate...–KnowledgeSeeekerMay 21, 2014 at 11:24Add a comment|
I have created one disk cleanup script which after cleanup sends a status email. now when I run this through command line, it executes perfectly but through cronjob its not able to send staus mail rest the script is working fine though. I have read many solutions in google but nothing is working for me. I am using Bash on my Ubuntu machine. here is sendmail part of my script.export CONTENT="/root/cleanup/cleanup.htm" export SUBJECT="Disk Space Clean Up Process : Completed @ $date_time" (echo "Subject: $SUBJECT" echo "`cat sendmail_list.txt`" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo "Content-Disposition: inline" cat $CONTENT )|/usr/sbin/sendmail -tplease help me know the solution...thanks
Sendmail is not working with crontab (bash)
Cron jobs are subject to a 10 minute deadline, not 30 seconds.SeeApp Engine version 1.4 release page:No more 30-second limit for background work - With this release, we’ve significantly raised this limit for offline requests from Task Queue and Cron: you can now run for up to 10 minutes without interruption.@Alex Martelli's answer was correct at the time he wrote it, but is now out of date.ShareFollowansweredOct 1, 2012 at 5:51speedplanespeedplane15.9k1717 gold badges8989 silver badges138138 bronze badges21This question also is now out of date.–poolieJun 25, 2016 at 0:031Am I the only one who absolutely hates this?–MagooDec 12, 2020 at 13:26Add a comment|
I have created a cron job to scan rss/atom feeds but want to know if there is a timeout on this.The documentation says that requests are limited to 30 seconds; is a cron job a regular request that is subject to this restriction?Should I break the job up into one scan per cron job just to be on the safe side, or is there a better way?I was thinking of maybe having the cron job spawn tasks into the task queue that would do the resource fetching (so each task could fetch one resource, and hopefully none would overrun the 30 second limit).Any advice would be appreciated.
Is there a time limit to Cron jobs in Google Apps?
Jenkins provides a helpful overview here. If you tick onBuild periodicallyin the job configuration, you can click on the question mark next toSchedule.I just want to quote one small part of it (it's always helpful to read the entire help yourself):This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:MINUTE HOUR DOM MONTH DOW MINUTE Minutes within the hour (0–59) HOUR The hour of the day (0–23) DOM The day of the month (1–31) MONTH The month (1–12) DOW The day of the week (0–7) where 0 and 7 are Sunday.[...]In addition, @yearly, @annually, @monthly, @weekly, @daily, @midnight, and @hourly are supported as convenient aliases. These use the hash system for automatic balancing. For example, @hourly is the same asH * * * *and could mean at any time during the hour. @midnight actually means some time between 12:00 AM and 2:59 AM.ShareFolloweditedApr 28, 2015 at 7:08Dave Bacher15.8k33 gold badges6565 silver badges8888 bronze badgesansweredApr 27, 2015 at 19:10volkervolker1,8251616 silver badges1515 bronze badges2I configured my build like this 31 11 * * 1-6 which 11:31 AM every workday. I don't see the build running under the build history but I ran and appeared in build history after finishing, Do I need to do some other config so that its visible while running?–WearybandsJul 4, 2018 at 11:39You didn't hyperlink your first sentence.–MoradnejadMay 5, 2019 at 8:44Add a comment|
What is the cron syntax for scheduling a Jenkins job:a) monthly b) weeklyThanks!
Jenkins - Build job monthly or weekly
use thiswget -q -O - http://example.com/backup >/dev/null 2>&1instead ofwget -q -O /dev/null "http://example.com/backup" > /dev/null 2>&1ShareFollowansweredJan 4, 2018 at 7:31Saeed AwanSaeed Awan43666 silver badges88 bronze badges2can we also use likeGET https://example.com/billing/?ng=console/0982995697/??–user2561540Mar 5, 2020 at 14:251We had to escape any&characters in the command, e.g., if the URL contains parameters. Maybe just a requirement of a particular version of CPanel. The example then becomeswget -q -O - http://example.com/backup?param=1\&param=2 >/dev/null 2>\&1.–adejonesFeb 18, 2021 at 8:51Add a comment|
i need to create cron job to run URL from Cpanel every minutewhen i open the link from browser it's auto generate backup for databasei choose the common setting ( once per minute ) * * * * *and this is the command i use but no one workedGET http://example.com/backup > /dev/nullwget http://example.com/backupcurl -s http://example.com/backup > /dev/nullwget -q -O /dev/null "http://example.com/backup" > /dev/null 2>&1this is my referenceshttps://forums.cpanel.net/threads/cron-job-to-call-a-web-page.60253/Using CRON jobs to visit url?CRON command to run URL address every 5 minutes
cron job to run url cpanel
I've never tried, but you should be able to do this by loading up the Rails environment in whenever so that you can use your model classes. Just userequire File.dirname(__FILE__) + "./environment"(or"./application"for Rails 3) in your schedule.rb, assuming your schedule.rb is in the config dir.However, since all whenever does is generate lines in the crontab, any changes made to anyConstantwould require runningwhenever --update-crontabagain.ShareFollowansweredJan 5, 2011 at 12:18idlefingersidlefingers31.8k55 gold badges8282 silver badges6868 bronze badgesAdd a comment|
Lets say I have a cronjob like this:every 1.day, :at => '4:30 am' do runner "MyModel.task_to_run_at_four_thirty_in_the_morning" endAlthough, I would like to make '1.day' more dynamic, such as changing the value via a form in an administration page.Then it could look like this:every Constant.find(2).value, :at => '4:30 am' door@const = Constant.find(2) every @const.span, :at => @const.time doCan anyone come up with an idea on how to make this work?Obviously, the reason for this would be that I could use the values stored in the database on my site, like an message saying<%= "The next update is in less than #{@const.time}" #or something similar %>
Rails - Whenever gem - Dynamic values
Oops. Guess I found the "why" or at least, the "how" :Onlyrenaming the job filename without ".sh" extensionsolved that issue.I thought it was a Debian's bug but it isn't, as described in the other answers below.SOLUTION: rename your script by removing all.or+characters from its nameShareFolloweditedMar 2, 2014 at 13:17answeredMar 30, 2011 at 13:01hornetbzzhornetbzz9,25655 gold badges3838 silver badges5353 bronze badges31It is specific to debian. It's not a bug, as far as they are concerned.–Glen SolsberryMar 30, 2011 at 13:031@gms8994: thx, but I did not find anywhere this point about job filenames. I found it on purpose, making dichotomial tests.–hornetbzzMar 30, 2011 at 13:072I found it the same way; seemy questionfor more information.–Glen SolsberryMar 30, 2011 at 13:13Add a comment|
This question already has answers here:CronJob not running(19 answers)Closed3 years ago.I have a bash scriptfoo.shlocated in the/etc/cron.dailydirectory, chmoded 700, owned by root, crontab list for the root user is unchanged (crontab -l) from the core Debian installation. I did run cronjob in another way than crontab -l and/or crontab -e (eg I did not restart cron daemon with /etc/init.d/cron as adviced in the specific Debian's case). Despite a test job file is running under similar conditions. The script is debugged and can be run as a standalone task without returning errors. I've also checked logs (/var/log/syslog) and nothing wrong in there.But: this particular job is not executed at all.
linux debian crontab job not executed [duplicate]
A line like20,40 * * * * /path/to/jobshould trigger the job only whenever the minute part of the time is 20 or 40.If you are putting this in the system's crontab, add a username after that last star.ShareFollowansweredJun 26, 2013 at 17:53cHaocHao85.6k2020 gold badges145145 silver badges173173 bronze badges1Oh it's that easy? I've been trying to figure it out for hours...(feels stupid). I'll go set this up and see how it goes, thanks!–user1729362Jun 26, 2013 at 17:55Add a comment|
How to run cron every 20mins so like this:00:20, 00:40, 01:20, 01:40 etc all the way but not at :00What should I put in crontab?
How to run cron every 20 minutes but not hour
You can do this with timeout (coreutils):30 23 * * * timeout 18000 /usr/bin/php /var/www/ul/prices_all.php >> /var/www/ul/log/prices_all.txtIt simply sets a timeout (18000secs = 5 hours) and kills the process if it is still running after that time.Or you can set a timeout in the php file itself:<?php set_time_limit(18000);ShareFolloweditedJan 31, 2013 at 22:43answeredJan 31, 2013 at 22:31Green BlackGreen Black5,07511 gold badge1717 silver badges2929 bronze badges560 (sec) * 60 (min) = 3,600 sec (1 hour). 9000 is unlikely to be 5 hours, unless I made a mistake.–mk_89Jan 31, 2013 at 22:34I would prefer to control the timeouts in crontab since I have so many cron jobs–mk_89Jan 31, 2013 at 22:46@GreenBlack How about in python? can we use method timeout?–Yohanes AIMay 14, 2018 at 6:57Have tried this*/2 * * * * timeout -s 9 60 cd /usr/etc && python2.6 hello.py 10.10.252.120 437 >> res.txtand not working–Yohanes AIMay 14, 2018 at 7:151because you have the timeout on the cd command - which happens instantly. move the timeout -s 9 60 part after the && and before the python2.6 part.–Shawn TolidanoJan 10, 2019 at 22:51Add a comment|
I basically have a cron job which runs every night that updates thousands of products in my database.The reason I run the cron job at night is because there will be less latency on the servers as not many people visit the site during this time, the cron job can pretty much run on for days without any interference.Here is what the cron job command looks like30 23 * * * /usr/bin/php /var/www/ul/prices_all.php >> /var/www/ul/log/prices_all.txtWhat I would like to know is would it be possible to create a cron job which kills this process after 5 hours e.g.30 05 * * * kill /var/www/ul/prices_all.php[process]
cron job that kills a process after 5 hours
Normally when processes are run from cron, thePATHis set to a very restrictive value (the man page for my crontab says/usr/bin:/bin). You may need to add:PATH=/usr/bin:/bin:/sbinto the top of your crontab file.ShareFollowansweredOct 21, 2009 at 18:54Greg HewgillGreg Hewgill969k186186 gold badges1.2k1.2k silver badges1.3k1.3k bronze badges0Add a comment|
I usepopento execute commands in a Python script, and I call it via cron.Cron calls out this script but the behavior isn't the same if I call it by hand.Source:from subprocess import Popen, PIPE pp = Popen('/usr/bin/which iptables', shell=True, stdout=PIPE) data = '' for ln in pp.stdout: data = data+ln if data == '': print 'ko' else: print 'ok : '+dataBy hand:# python /home/user/test.py > : /sbin/iptablesBy cron (in /tmp/err_cron):* * * * * /usr/bin/python /home/user/test.py >> /tmp/err_cron ko ko koWhy does cron not run this script normally?
Python problem executing popen in cron
The reason why you don't get the fileforecast.txtin directory/home/valencewhen using crontab job* * * * * /home/valence/Get_forecast.pyis that the cron don't execute the command in directory/home/valenceand you specified the fileforecast.txtin relative path form in your program. So the file is created somewhere else.To get the expected file output, you can use the following crontab job:* * * * * cd /home/valence && ./Get_forecast.pyThis explicitly assign the current working directory to be/home/valence, and execute the script from there.What's more, to get the output from stdout and stderr, add redirection is always helpful when something unexpected happens:* * * * * cd /home/valence && ./Get_forecast.py > /tmp/forecast.log 2>&1Note:The previous two crontab job assumes Get_forecast.py jexecutable and with shebang specified. The./Get_forecast.pypart can always be replaced withpython3 Get_forecast.pyor/usr/bin/python3 Get_forecast.pyto be more clear.ShareFollowansweredJan 12, 2016 at 4:34greenqygreenqy68677 silver badges77 bronze badges1Could someone explain what changes are required to make the cron job run:* * * * * /home/valence/Get_forecast.pyrather than having to cd dir and execute the script?–benscabbiaSep 7, 2017 at 20:33Add a comment|
I have a python3 script located in /home/valence/ that gets the weather forecast for the current day (max and min temperature values in Celsius) from Yahoo! weather API. The file looks exactly like this:#!/usr/bin/python3 from urllib import request import json url="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D349859%20and%20u='c'&format=json&diagnostics=true&callback=" response=request.urlopen(url) str_response = response.readall().decode('utf-8') dic = json.loads(str_response) dic["query"]["results"]["channel"]["location"]["region"]="R.M." low=dic["query"]["results"]["channel"]["item"]["forecast"][0]["low"] high=dic["query"]["results"]["channel"]["item"]["forecast"][0]["high"] forecast=open("forecast.txt", "w+") forecast.write("Minima: "+str(low)+" Maxima: "+str(high)) forecast.close()It works fine when I execute it. It creates or overwrites the file forecast.txt with the right values, but when I try to use cron to execute with the following cron job:* * * * * /home/valence/Get_forecast.pyno file forecast.txt is created or modified.So I need to know what I am doing wrong and how to make this work as intended. The cron job is not meant to be executed every minute (because forecast for a day remains the same throughout the day), but for now I have it that way so I can see changes without having to wait much.Note: I am new to linux (I am using Lubuntu)
Executing python3 file with a cron job.
Try giving the whole path.Find which pipenv and then run with the absolute path of the same. instead of pipenv -hIn my case it was located in/usr/local/bin/pipenvShareFollowansweredJan 19, 2018 at 13:32VaradVarad1,0001111 silver badges2626 bronze badges3Thank u, But I can not find the path. It was not located in/usr/local/bin/pipenvin ubuntu. I used pip3 install pipenv. Do u know how to find the actual path in ubuntu16.04?–beehuangJan 19, 2018 at 14:031Thank u I found in /home/ubuntu/.local/bin–beehuangJan 19, 2018 at 14:155For future reference: Runningwhich pipenvshould say where pipenv is located :)–thomasa88Jun 16, 2018 at 13:27Add a comment|
I have installed pipenv by pip3.And it works pipenv -h in script.But after in crontab, it's not work.pip3 show pipenvLocation: /home/ubuntu/.local/lib/python3.6/site-packagesmy cronjob21 * * * * cd /home/ubuntu/test; /bin/sh test.sh > /home/ubuntu/test.out 2>&1test.sh#!/bin/bash echo "hi" python -V python3 -V pipenv -houtput hi Python 2.7.12Python 3.6.3test.sh: : test.sh: pipenv: not foundhow to run pipenv in cronjob in ubuntu? thanks.Answer:/home/ubuntu/.local/bin/pipen
how to run pipenv in cronjob in ubuntu?
Instead of putting in cronjob command likephp -f /path_to_script/script.phpput command like this:curl http://domain.com/yourscript.phpif you want to suppress output you can add> /dev/nullat the end.So full command would be:curl http://domain.com/yourscript.php > /dev/nullHope this helps!ShareFollowansweredNov 1, 2012 at 17:49alan978alan97853533 silver badges66 bronze badges2Finally ! This is the only working answer I found, thanks a lot, great idea–AymDevApr 8, 2018 at 17:04It may not work with addon domains though (use absolute path to make it work there).–TomaszJan 20, 2019 at 0:31Add a comment|
I have setup cron job, it is working properly, however when i directly runs the php file(from the path/url) it successfully runs, but from cron its not. However i set another very simple file to make sure my cron command/path is set correctly i created another file and used simple php mail function and its is running successfully. Kindly suggest me the possible areas to look into it. (I am using Cpanel)
Cron job is not working properly in cpanel
You can use S3 lifecycle policy by Following steps:Click on your S3 property and select Lifecycle tab and click Add rule.Click on Configure Rule.Check permanently delete and enter seven days(or any other number you want) and click on review.Enter rule name and click on "create and activate rule".Check your rule created successfully and enjoy.ShareFolloweditedJun 20, 2020 at 9:12CommunityBot111 silver badgeansweredJul 24, 2016 at 10:49Reza MousaviReza Mousavi4,51055 gold badges3131 silver badges4949 bronze badgesAdd a comment|
I would like to delete the back up files that is older than 1 week. I have followed thisbackup documentfrom gitlab and successfully create the backup files to upload to Amazon S3.I have also set upgitlab_rails['backup_keep_time'] = 604800but it does not work.However, from what I observe in the IAM user policy they created. There is no authorization to delete the files.The backup files are packing up and I would not want to do this manually in AWS.Is there any standard way to delete the backup files in Amazon S3 for gitlab omnibus package?{ "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1412062044000", "Effect": "Allow", "Action": [ "s3:AbortMultipartUpload", "s3:GetBucketAcl", "s3:GetBucketLocation", "s3:GetObject", "s3:GetObjectAcl", "s3:ListBucketMultipartUploads", "s3:PutObject", "s3:PutObjectAcl" ], "Resource": [ "arn:aws:s3:::my.s3.bucket/*" ] }, { "Sid": "Stmt1412062097000", "Effect": "Allow", "Action": [ "s3:GetBucketLocation", "s3:ListAllMyBuckets" ], "Resource": [ "*" ] }, { "Sid": "Stmt1412062128000", "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::my.s3.bucket" ] } ] }
Gitlab Omnibus: Delete backup from Amazon S3
The commandswgetandcurlcan be used (fairly) similarly if you just want to download something from a URL. Note that the following is available in themandocumentation for each command.Syntaxwget [options] [URL] curl [options] [URL]OptionsTo specify a download location,wgetuses-Owhilecurluses-o.To silence output,wgetuses--quietwhilecurluses--silent.To delete every file that is downloaded upon completion,wgetuses--delete-after. I don't believecurlhas a related option (orit may do this automatically).So a direct translation of your first command would be:wget https://www.yoursite.com/index.php?route=cronjob/cronjob -O /dev/null curl https://www.yoursite.com/index.php?route=cronjob/cronjob -o /dev/nullMake sense?There arelots of examplesonline and extensive documentation on themanpage for each command.ShareFolloweditedJul 30, 2014 at 19:00answeredJul 30, 2014 at 18:53Casey FalkCasey Falk2,64711 gold badge1818 silver badges2929 bronze badges1in my case I replaced with curl myadres >> outName.sh–SkorpENFeb 16, 2021 at 18:19Add a comment|
I would like to change the following wget cron commands to curl format:wget https://www.yoursite.com/index.php?route=cronjob/cronjob -O /dev/null wget --quiet --delete-after "http://www.yoursite.com/index.php?route=cron/abandoned_cart_reminder&secret_code=yourcode"Thank you!
convert wget cron command to curl
*/15 11-18 * * * statement/to/run 0 0-10,19-23 * * * statement/to/runShould do what you need.*/15 or 0,15,30,45 will both do the same thing and run every 15 minutes.You'll need to break it into two entries since you want it to run differently during different times of day.ShareFolloweditedOct 30, 2012 at 10:27answeredOct 30, 2012 at 10:22OmnikrysOmnikrys2,5381919 silver badges1313 bronze badgesAdd a comment|
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed11 years ago.Improve this questionI have to run daily cron.Cron must running time will be morning 11 AM to evening 7 PM.In this given time cron must run at every 15 mins daily.same thing after in night cron must run at every hour?Is this possible with linux cron scheduling type.Or i have to manage this from any scripting language.
setup cron from morning to evening only [closed]
This is the solution that i used...When there is no recurence i use a cron trigger and select the days and make it run every weekE.G. 0 0 * * 1,2,3when there is recurence for each selected day i add a SimpleTrigger, bassically the start date is the day of the week, and then i calculate the recurrence by multiplying the recurence for 7So i will end up wit one simpletrigger for each day.I hope this helps someone else!ShareFollowansweredFeb 2, 2011 at 23:06Bongo SharpBongo Sharp9,52088 gold badges2525 silver badges3535 bronze badgesAdd a comment|
i need to implement the following scenario using Quartz.NET:Recur every n week(s) on:Sunday and/or Monday, Tuesday, Wednesday, Thursday, Friday, Saturday...So for example i might select: monday and thursday, and recur every 2 weeks, is this possible?I figure it out that the way to go might be using Cron Expressions, but i haven't had luck so far with the "Recur Every X Weeks"Thanks!
Quartz.NET, Recur Every x Weeks
The accepted answer above is INCORRECT. Cron's time limit in Drupal is hardcoded to 240 seconds. See thedrupal_cron_runfunction inincludes/common.inc, specifically these lines:drupal_set_time_limit(240);andif (!lock_acquire('cron', 240.0)) {(based on the source of Drupal 7.12)So, there is no way to change this globally without hacking core. I have heard it suggested to calldrupal_set_time_limityourself inside of yourhook_cronimplementation, as doing so resets PHP's counter. However that won't help you when it's a third-party module implementinghook_cron.ShareFollowansweredFeb 9, 2012 at 23:19feedbackloopfeedbackloop49111 gold badge66 silver badges1515 bronze badges1As of Drupal 8.7, the number is still 240 seconds, but it is set inweb/core/lib/Drupal/Core/Cron.php:Environment::setTimeLimit(240);–froboyOct 24, 2019 at 18:44Add a comment|
Whats the maximum execution time of cron. is it possible to modify it if so any side effects.
drupal maximum execution time of cron
Try something like this// version 1 cron.schedule("*/2 * * * *", this.servicesManager.startPoll); // version 2 => if servicesManager needs its `this` reference cron.schedule("*/2 * * * *", async () => this.servicesManager.startPoll()); //version 3 ==> using node-schedule schedule.scheduleJob("*/1 * * * *", async () => this.ServicesManager.startPoll());I don't know about yourservicesManager, you might have to use "version 2" from above to get it to work.The schedule libraries need a function to execute, but instead they get a resolved Promise in the examples above.ShareFolloweditedSep 3, 2020 at 6:01answeredOct 21, 2019 at 11:42krafkraf1,2791212 silver badges2121 bronze badges2This is part of nodejs based rest api server code , The ServicesManager is the wrapper around fucntional calls , the controller makes the calls from ServiceManager, version 1 and 2 is not working , similar way i am trying with schedule.scheduleJob("*/1 * * * *", async () => { this.ServicesManager.startPoll(); }); Here , ServicesManager calls startPoll which calls another async function and startPoll itself retruns async–cslrnrOct 21, 2019 at 12:38None of the code lines in the answer are syntactically correct.–AF7Sep 1, 2020 at 14:39Add a comment|
I want to schedule a function which is asynchronous (async/await ruturn type) to run for every two minutes.I tried with genericsetInterval, node modules likenode-schedule , cron, node-cron, async-pollbut unable to achieve polling for a async function call.This is what I tried in code:cron.schedule("*/2 * * * *", await this.servicesManager.startPoll() => { console.log('running on every two minutes'); }); // this is not working breaks after first run const job = schedule.scheduleJob(" */1 * * * *", async function() { try { return await this.ServicesManager.startPoll(); // this function startPoll is undefined when using this } catch (e) { console.log(e); } console.log('Run on every minute'); }); const event = schedule.scheduleJob("*/2 * * * *", this.ServicesManager.startPoll()); //using node-schedule , breaks after first time cron.schedule("*/2 * * * *", await this.ServicesManager.startPoll()); // using cron same result as using node-schedule return await this.ServicesManager.startPoll(); // without polling works
Schedule an async function in NodeJS
+50See:wp_schedule_event()Valid values for the recurrence are hourly, daily, and twicedaily. These can be extended using the ‘cron_schedules’ filter in wp_get_schedules().So you just need to add a custom schedule that runs every 5 minutes.<?php // Requires PHP 5.4+. add_filter( 'cron_schedules', function ( $schedules ) { $schedules['every-5-minutes'] = array( 'interval' => 5 * MINUTE_IN_SECONDS, 'display' => __( 'Every 5 minutes' ) ); return $schedules; } ); if( ! wp_next_scheduled( 'my_function_hook' ) ) { wp_schedule_event( time(), 'every-5-minutes', 'my_function_hook' ); }ShareFolloweditedNov 17, 2017 at 9:38answeredNov 15, 2017 at 23:29jaswrksjaswrks1,2751010 silver badges1313 bronze badges1I'm aware WordPress cron works differently - this was the issue, I passed the wp_schedule_event() function a number rather than a valid schedule, thanks for your help jaswrks–user3574766Nov 23, 2017 at 14:32Add a comment|
I'm creating a WordPress plugin, when the plugin is activated I need a cron job to be scheduled to run every 5 minutes.Here's my code;// Register plugin activation hook function my_plugin_activate() { if( !wp_next_scheduled( 'my_function_hook' ) ) { wp_schedule_event( time(), '5', 'my_function_hook' ); } } register_activation_hook( __FILE__, 'my_plugin_activate' ); // Register plugin deactivation hook function my_plugin_deactivate(){ wp_clear_scheduled_hook('my_function_hook'); } register_deactivation_hook(__FILE__,'my_plugin_deactivate'); // Function I want to run when cron event runs function my_function(){ //Function code } add_action( 'my_function_hook', 'my_function');When I use this pluginhttps://wordpress.org/plugins/wp-crontrol/to check the cron events, nothing has been added, I'm expecting a cron event to be added that runs 'my_function' at 5 minute intervals, I have no errors
wp_schedule_event() in plugin not scheduling a cron event
I created this Scheduler which runs once a minute and is part of your own app.https://gist.github.com/robbydooo/65bf341ea0f4081150b945bfb1d38d3cIt creates a new Dyno type called Scheduler which you start one of.Make sure you run jobs on your queue to avoid this scheduler over running once per minute.To use this scheduler with Laravel 5.4+ add this file to /app/Console/Commands/RunScheduler.php Register this file in app/Console/Kernel.phpprotected $commands = [ … Commands\RunScheduler::class … ]Add this line to your Procfile:scheduler: php -d memory_limit=512M artisan schedule:cronShareFolloweditedJun 1, 2017 at 17:49Fester87311 gold badge1212 silver badges3333 bronze badgesansweredMar 8, 2017 at 22:13Robert NormanRobert Norman19122 silver badges55 bronze badges1i tried the same , but not reflecting the memory limit issue. Meantime web is working fine with Procfile–jpkOct 26, 2017 at 19:32Add a comment|
I'm trying to follow the Laravel Documentation onhow to Run Cron Jobs, and I want to add this* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1But I don't know how to add it to Heroku.
How to setup Laravel 5's task scheduling in Heroku?
You just need to use escaping%sign* * * * * touch /tmp/foo_`date '+\%m-\%d-\%Y'`.txtResult:[root@linux tmp]# ls -l /tmp/foo_* -rw-r--r-- 1 root root 0 Apr 18 02:17 /tmp/foo_04-18-2015.txtShareFollowansweredApr 17, 2015 at 20:50SatishSatish16.9k3030 gold badges9999 silver badges155155 bronze badges4Neither of these work, I did some research and found out that shell is not, by default, accessible from the cron tab. I still have not solved the issue, but I believe this to be the cause.–JasonApr 20, 2015 at 15:54what do you mean shell isn't accessible from crontab? cron use defaultSHELL=/bin/bashvariable–SatishApr 20, 2015 at 16:35Ok.. So my shell path was incorrect, THEN adding backslash to escape fixed my issue! Thank you guys so much..–JasonApr 20, 2015 at 19:02if you find answer is help full then please click onAnswerto get point–SatishApr 20, 2015 at 19:24Add a comment|
I am having an issue that I can not find any information for while doing an extensive google search.I have a linux cron, running via crontab, that works great until I try to add a variable date to the title of the file. BUT.. When I run the same command outside the cron, just from the command line, it works fine.. Also, the cron does work if I take out the date part.Command line code that works:sudo mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gzCron that works:15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database.sql.gzCron that DOESN'T work:15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gzI am not understanding why I can not use the date function while inside a cron? Everything I find says I can, but in practice, I can not.Server details: Ubuntu 12.04.5Thank you for any insight.
Variable date not working in linux cron
You're probably long past this issue but for future reference:I had a similar problem only I was getting/usr/bin/env: ruby: No such file or directoryIt turned out the first line of the file script\rails was#!/usr/bin/env ruby1.9.1, which tells the system to invoke it with ruby1.9.1 as explainedhere. But it should have been#!/usr/bin/env ruby1.9.3since that was the version I had installed.Hope this helps someone in the future :)ShareFolloweditedMay 23, 2017 at 11:46CommunityBot111 silver badgeansweredAug 13, 2012 at 19:12TamarTamar2,02611 gold badge1515 silver badges2626 bronze badges11It would have been better to specify the path of the file (inside the application folder)–skvJan 18, 2015 at 17:36Add a comment|
When using the 'whenever gem', I get an error in the log:/usr/bin/env: ruby: No such file or directoryIt works when I run the job manually. I've installed everything with RVM.I've used thewhichcommand to find where my Ruby installation is, and I get:kevin@lovely:/opt/personal$ which ruby /home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin/rubyand I've checked my $PATH variable, where it returns:kevin@lovely:/opt/personal$ echo $PATH /home/kevin/.rvm/gems/ruby-1.9.2-p290/bin:/home/kevin/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gamesI believe this should be set up right, but I'm probably wrong since it doesn't work. Can anyone point me in the right direction?If you're interested, this is what my whenever crontab output is:# Begin Whenever generated tasks for: rss 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /opt/personal && script/rails runner -e development '\''FeedEntry.update_from_feed("http://lovely/blog/feed/")'\'' >> /opt/personal/log/feedzirra.log 2>&1'
Rails 3 - Whenever gem error: /usr/bin/env: ruby: No such file or directory
I usually just write a rake task and add it to CRON.The rake task will look like this:namespace :notifications do desc "Sends notifications" task :send => :environment do MyModel.all_users_to_notify.each do |u| MyMailer.notification(u).deliver end end endAnd your crontab should look like this:RAILS_ENV=production HOME=/path/to/your/rails/app PATH=/path/to/ruby/binaries 30 17 * * * rake notifications:sendShareFollowansweredOct 15, 2010 at 13:34Fábio BatistaFábio Batista25.2k33 gold badges5757 silver badges6969 bronze badges2I forgot => :environment, and it won't work, can you explain me why? thanks so much!–duykhoaNov 9, 2012 at 10:512You use the hash syntax to declare task dependencies. There's a task named:environment, which only purpose is to load the Rails environment. If you omit the=> :environmentdependency, your task will work outside of your Rails environment, thus booting up faster and with a lower memory footprint. This could be useful sometimes, like deleting temp files etc.–Fábio BatistaNov 13, 2012 at 18:00Add a comment|
What exactly would be the best way to go about using a cron task to send daily e-mails of updates to all users on my network? The e-mail would be made up of different information from multiple models.I want to do something like "1 new friend requests :name..." from the request model and user model and "There are 3 upcoming events from your friends:event namehosted byname..." from the event and user model.I realize this is a common task but I didn't see much information on it, so any general tips about doing something like this would be greatly appreciated!Side note: I will be using the Heroku daily cron plug-in to accomplish this if that matters (although I don't think it should).
RoR: Using CRON and Actionmailer to send daily email updates to all users
Try this:ps aux |grep 'part_of_the_name_of_your_script'|awk '{print $2}' |xargs kill -9 {}Or in your crontab file use crun and variableCRUN_TIMEseecrun -hShareFolloweditedAug 5, 2013 at 18:17answeredAug 5, 2013 at 18:12WebeithWebeith31311 silver badge88 bronze badges11killer one liner, thank you. I got error with{}, command worked when I removed it.–Sandip PingleJan 22, 2015 at 11:53Add a comment|
I have scheduled a CRON which calls/executes a PHP script every five minutes. PHP script perform following tasksChecks for the flag value in database to identify if the previous run is still executing. Value of 1 in the DB tells that process is still running while a value of 0 means it is not.If the flag value is 1, then exit the PHP else continue to next step.Update the flag value in database from 0 to 1.Execute the business logic.Update the flag value back from 1 to 0, so that next CRON can executes if the data is available in user tables.All works fine so far, depending on the size of user uploaded data the process on an average takes 35 to 40 minutes to complete.Question, Is there anyway to kill or stop the execution of PHP script once started by cron. May be a button to let users stop the execution, upload new data and wait for CRON run. I can take care of reseting all the flags and data it's just the kill of PHP script is what i am trying to figure out.I did some google and figured i can use some commands like:Killall -9 PHPto kill all php processes running on server, but not sure how to do this through PHP.
Kill or stop execution of PHP script initiated by CRON?
My Postfix configuration was wrong. I needed to use the following:smtp_sasl_auth_enable = yes smtp_sasl_password_maps = static:<username>:<password> smtp_sasl_security_options = noanonymous smtp_tls_security_level = may header_size_limit = 4096000 relayhost = [smtp.sendgrid.net]:587Sending the email via bash script is done as follows:sendmail[email protected]<<EOF subject:This is a test from:[email protected]Body message here... EOFShareFolloweditedJan 10, 2015 at 22:24Flexo♦87.9k2222 gold badges194194 silver badges277277 bronze badgesansweredMay 9, 2013 at 8:35josef.van.niekerkjosef.van.niekerk12k2020 gold badges9999 silver badges159159 bronze badgesAdd a comment|
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed7 years ago.Improve this questionI'm trying to write a bash script, to be run by a cron task, which will send me an email under certain circumstances.In order to try and get sendmail working with my Sendgrid SMTP settings, I've edited the/etc/postfix/main.cffile with the following:smtp_sasl_password_maps = static:<username>:<password> smtp_sasl_security_options = noanonymous smtp_tls_security_level = may smtp_tls_security_level=encrypt header_size_limit = 4096000 relayhost = [smtp.sendgrid.net]:587I restarted postfix usingsudo /etc/init.d/postfix restartAnd tried sending an email from the command line using the following command:sendmail[email protected]< /tmp/email.txtThis results in the following output:You have new mail in /var/mail/ubuntuWhy isn't sendgrid sending with my email using the Sendgrid SMTP details I specified in main.cf?Please note, this question relates to sendmail only, I don't want to install other SMTP clients and apps, it needs to work as is.
Using sendmail from command line [closed]
Just found this, was exactly what I was looking for and it seems like what you want too:http://cronchecker.net/ShareFollowansweredJul 19, 2012 at 18:41Jasdeep GosalJasdeep Gosal60655 silver badges77 bronze badges32This one is not able to parse this cron: 30 07,11 * * 1-6 and some others too.–GuillaumeNov 6, 2013 at 8:30@Guillaume: I recently rebuilt cronchecker.net and it can handle many more cron statements that it couldn't previously, including the one you mention. Pleaselet me knowif you run into any more that don't work properly.–pbyrneMay 14, 2014 at 1:33@pbyrne Doesn't parse00 30 22 * * *. Displays the message:We're sorry, but something went wrong. If you are the application owner check the logs for more information.–Kshitiz SharmaJun 15, 2015 at 15:49Add a comment|
Closed.This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meetStack Overflow guidelines. It is not currently accepting answers.We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.Closed7 years ago.Improve this questionDoes anyone know of a tool that will given a cron string for example * * * 1 * * tell you what that string translates to?I know it's not rocket science but I want to be sure that I'm constructing the correct interval for a scheduled task.
Cron syntax interpreter? [closed]
If you installed ruby via rvm, ruby probably isn't in /usr/bin. Depending on where rvm is installed:bash -c "source /usr/local/lib/rvm" && rails runner foo.barYou probably added a source*/rvm to your bashrc that is the correct rvm loading script.ShareFollowansweredMar 9, 2011 at 5:13drewrobbdrewrobb1,5941010 silver badges2424 bronze badges1I found out the reason why: the ruby is not registered in crontab shell. And I did following: /bin/bash -c "source /usr/local/rvm/src/rvm/scripts/rvm && /root/a/a_rails/script/rails runner Foo.bar"–c2h2Mar 9, 2011 at 6:28Add a comment|
I have install ruby by rvm (system-wide), and worked correctly via normal console and my rails program is behaving correctly with bothrails runnerandapache2+passenger.Now in a crontab, I calledrails runner foo.bar, it gives up, carefully examine the log i see that:/usr/bin/env: ruby: No such file or directoryAnyone knows why /usr/bin/env doesnt work in crontab?
why #!/usr/bin/env ruby doesn't work in crontab?
You can directly edit the following files:/etc/crontab /etc/cron.d/* /etc/cron.{hourly,daily,weekly,monthly}/*These are system-wide files. In these files you must specify a username before the command to be executed.In contrast, per-user crontabs are stored here:/var/spool/cron/<username>ShareFolloweditedDec 24, 2020 at 20:15Gogowitsch1,21211 gold badge1313 silver badges3333 bronze badgesansweredApr 5, 2013 at 9:21MadoxMadox15611 silver badge44 bronze badges3Edit just to format your answer.–fedorquiApr 5, 2013 at 9:51I'm a newbie here. Don't not get used to parser yet.–MadoxApr 5, 2013 at 19:421Note: the user crontab/var/spool/cron/<username>should not be edited without the crontab command. When opening the file with a text editor, it says# DO NOT EDIT THIS FILE - edit the master and reinstall..–baptxMay 14, 2021 at 19:17Add a comment|
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed10 years ago.The community reviewed whether to reopen this question1 year agoand left it closed:Original close reason(s) were not resolvedImprove this questionIs it possible to add a cronjob without using the crontab command? (Or anything else except editing files directly.) Is there a file I need to edit?
Adding a cron job without crontab [closed]
Yes,Quartzhas a special character --L ("last")--, which allows you to define expressions such asthe last friday of the month.To fire a job at, say, 10am, on the last Thursday (5L) of every month, you can use the following cron expression:0 0 10 ? * 5LShareFolloweditedAug 14, 2012 at 13:06answeredAug 14, 2012 at 12:58João SilvaJoão Silva90.2k2929 gold badges153153 silver badges158158 bronze badges1How would you do the penultimate Thursday of every month?–brianaryFeb 25, 2020 at 21:03Add a comment|
I am using Quartz Scheduling and Spring Batch and I need to run a particular job on the last Thursday of every month.Is it possible to create such a Quartz cron expression?Thanks,
Quartz cron expression - last thursday of every month
FromHow can I set cron job through PHP scriptbyNick Clark:This will add a script that runs every day at 9:30am.exec('echo -e "`crontab -l`\n30 9 * * * /path/to/script" | crontab -');You may run into problems with permissions if you are running this script from a web server. To get around this, I would suggest a different approach.Here is one possible solution. Create a list of scripts that need to be run. You can save this in a text file or in a database. Create a script to read this list and run it every minute or every 5 minutes (using a cronjob). Your script will need to be smart enough to decide when to run the list of scripts and when to simply exit.You can do like this..Other links:Install a cron job with a php scriptHow to invoke cron job from php script?ShareFolloweditedJun 20, 2020 at 9:12CommunityBot111 silver badgeansweredJul 23, 2012 at 12:55FrontEnd ExpertFrontEnd Expert5,73988 gold badges5959 silver badges9999 bronze badges1i tried this , i just want to know after this i have to run my php file in browser ? i really don't have any idea how that cron will execute. can please explain it :(–suganyaJul 23, 2012 at 13:08Add a comment|
i am new to cron job . i studied some basics about cron job . i can able to call php using cron tab. By using following command in /etc/crontab10 * * * * root /usr/bin/php /var/www/PATH TO SCRIPT/email.phpIn email.php i have following code#!/usr/bin/php <?php mail ("[email protected]", "Cron Successful Public HTML!","Hello World from mycron.php!"); ?>For every 10mins i am getting mail. But i need to know is there any way to call cron job from php ( invoke cron from php) i get some idea by surfing but i am not able to figure out the exact way to do my job . Here is code which i used to add job by using phpexec('echo -e "crontab -e \n2 * * * * /usr/bin/php /var/www/PATH TO THE SCRIPT/crontest1.php" ');Its not working for me. can anyone please guide me how to call or add cron from php. so tat i can send mail by executing php file & can able change time interval in php file itself.
how to set cron job from php script?
I have used and like quartz. Here are some advantages of quartzIf you use an OS based cron the jvm would go up and down and any state would be lost.it is portable (can run on Win OS where no cron available)You can schedule multiple threads within quartzWe run our scheduler in tomcat and so we can manage and see the state of the app via admin web pages. In our app we use jamon to monitor the state of our processes. It can answer such things as... Which processes are currently running? When did they last run? How long did they take? etc. cron would not allow this.Your code would be more portable. Scheduling is done differently in different OS's.Probably quartz should be seen more as a replacement for launching new threads than as a replacement of cron.partially stolen fromhereShareFollowansweredFeb 28, 2012 at 8:03aviadaviad8,24999 gold badges5353 silver badges9999 bronze badgesAdd a comment|
Was planning to move from setting up cron jobs to Quartz scheduler. What are the pros/cons of using Quartz rather than setting up cron ?Got thisTime triggered job Cron or Quartz?link. Any other pointers ?
Quartz scheduler vs setting up cron
I've used the cron/wget solution and it's actually a reasonable way to solve the problem. Your system administrators will appreciate being able to control it.Another solution is to use a JVM system property to indicate which of your instances is the one that runs the jobs. For example:-DschedulerEnabled=true. Only set that flag on one of the instances and have the job scheduling code only run if that flag is set.Finally, Quartz supports your DB based solution with it'sClusteringfeature. The advantage of this is that it's a really a HA solution. With the other solutions if the machine that is acting as the job scheduler goes down you have to manually fail over to another machine.ShareFollowansweredNov 3, 2011 at 4:15sourcedelicasourcedelica24k77 gold badges6666 silver badges7474 bronze badges1Also, just found rcron which may solve it as well:code.google.com/p/rcron–razzedJun 11, 2015 at 18:02Add a comment|
We are hosting our website in AWS. We currently have 3 EC2 instances in one cluster, using the AWS load balancer.The servers have linux, apache, java, mysql, and tomcat 6.0.We are making a decision on how to set up a task to run every hour. The obvious place to do this is in the Java code, but there is one problem.The problem is that since we have 3 instances in the cluster (all are identical), the task will run 3 times on the hour, instead of once an hour, once per instance.I have a few ideas to overcome this but was hoping that there is a better, possibly an industry standard, on how to manage this.One idea is to store in the DB that it has already run. The task will see that it has already ran today or not. I see bugs there though.The other idea was to use cron installed on one of the instances in the native OS, outside of the code in Tomcat. This would use wget to call a webpage which calls a java method. Since that would only call one of the instances, it should only run once.Both ways seem like hacks and prone to bugs. Is there a real way to do this?
How to set up a CRON Task to only run once per set of instances?
You should indicate ${PATH_TO_PHP} into the cronjob, like :-* * * * * ${PATH_TO_PHP} /home/easybr01/domains/easybranding.nl/public_html/cronjobs/test.phpAlternatively, you can make the script executable (ex. mod 744),and place#!${PATH_TO_PHP}into first line of your PHP script, like :-#!${PATH_TO_PHP} <?php // remanding code ?>ShareFolloweditedNov 26, 2011 at 14:49answeredNov 11, 2010 at 19:35ajrealajreal47k1111 gold badges9393 silver badges119119 bronze badges2I've changed the chmod and added the path to PHP, waiting a minute now to see the effect.–BenNov 11, 2010 at 19:45Thankyou it worked now! And after many many times I started realized another thing I did wrong.. I put a 1 instead of a * in the minute field... which obviously means it should only execute the job every 1st minute of an hour. Thanks a lot!–BenNov 11, 2010 at 19:55Add a comment|
Maybe a silly question, but I'm trying to get a cronjob to work. Although this could be a question for serverfault I think its also a SO-question.Anyway: I have set up a cronjob to be executed everey 1 minute of every hour, day (number), day (name) and month. The given command is: /home/easybr01/domains/easybranding.nl/public_html/cronjobs/test.phpWhich is nothing more than a file with a simpe php functionmail(to, subj, content, hdrs)to test if it works... but the mails never come in.. and they're not in a spam folder eighter..Does someone know what's wrong?? I figured this should be pretty straight forward...
My cronjob isn't working?