Failing Cronjob in TYPO3 - Malformed parser URI - direct_mail - cron

At the moment scheduler tasks of EXT:direct_mail are failing. The cronjob gets the wrong URL.
http:///usr/www/users/myuser/myproject/current/typo3 which breaks setting up a draft mail with direct mail schedular.
["code"]=>
int(1436717322)
["message"]=>
string(96) "The parsedUri "http:///usr/www/users/myuser/myproject/current/typo3" appears to be malformed"
["file"]=>
string(90) "/usr/www/users/myuser/myproject/releases/48/Web/typo3/sysext/core/Classes/Http/Uri.php"
["line"]=>
Our cronjob:
* * * * * /usr/bin/php74 -d allow_url_fopen='on' -d allow_url_fopen='on /usr/www/users/myuser/myproject/current/typo3 scheduler:run > /dev/null 2>&1

The problem is partly because TYPO3 uses the HTTP_HOST variable to create absolute URLs. This is available by default when invoked via CLI. Then it can happen that the path on the server is used instead of the domain. It was finally solved by setting the cronjob like this:
* * * * * env HTTP_HOST=www.my-domain.com /usr/bin/php74 -d allow_url_fopen='on' /usr/home/username/public_html/myproject/current/typo3 scheduler:run > /dev/null 2>&1
This ensures that the HTTP_HOST variable is available.

Related

Get the url of cron job

I have to find the url from where the cron job calls an API.
I tried <?=$_SERVER['HTTP_HOST'];?> in the cron file but it returned empty and also <? phpinfo() ?> did not help.
Cron command: * * * * * php -q /home/karenib/public_html/scr/cron.php
The <?=$_SERVER['HTTP_HOST'];?> will will not be populated when running it from a cronjob like php -q /home/karenib/public_html/scr/cron.php, since the file is not accessed via HTTP.
You can pass the host through params like
php -q /home/karenib/public_html/scr/cron.php -h=http://example.com
And access it like
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : getopt('h:');
However, if you still need the HTTP_HOST populated, you can use curl like
curl http://example.com/path/to/cron.php &> /dev/null

cron job not running in goDaddy shared host for laravel 5.2

I am trying to run cron job in my laravel 5.2 application hosted in goDaddy shared host.
I have cPanel access and there I added a cron job, something like this:
* * * * * php /home/path/to/artisan schedule:run 1>> /dev/null 2>&1
But the issue is that the server is not calling schedule action in Kernel.php. The same works fine in my local system.
Can anyone point out the mistake please or suggest some way to accomplish this so that server runs the cron job so as to execute defined commands.
Add path of php binary to cron command.
* * * * * path/php /home/path/to/artisan schedule:run 1>> /dev/null 2>&1
Example : /usr/bin/php
Cpanel Cron job command in laravel godaddy and others are same
/usr/local/bin/php /home/ivlssadmin/public_html/inventoryproject/artisan OpeningStocks:openingstocks >> /dev/null 2>&1
Here what you change follow bellow :
/usr/local/bin/php /home/Your Host User Name /public_html/Sub Domain Name/artisan Command Name:Command Name >> /dev/null 2>&1
if you don't have sub domain you write only public html
Make sure you write the correct command in the schedule action. e.g. $schedule->command('send:followup')
Also check the timezone of the crontab if possible are you using utc timezone in your commands this is the default for most servers.

Cronjob command not working, despite having the same format as other commands that DO work

Trying to add a new cronjob to my server using Plesk. I have two running already, but it's so long since I set them up that I can't remember why I did it the way I did. They work exactly as they should.
*/13* * * * &> /dev/null php -q httpdocs/forum/notifyreply.php
*/9 * * * * &> /dev/null php -q httpdocs/forum/notifytopic.php
However, when I add my new job using the same format, it doesn't seem to do anything. The script doesn't run and I get no e-mail notification to tell me that the script has run. The new job is as follows:
* * * * * &> /dev/null php -q httpdocs/crm/autoMessages/autoEmail.php
I'm running these on a Linux Virtual Server with Apache and using Plesk Control Panel. Hosting provider is 123-Reg.
Can anyone help?
Thanks!
UPDATE
So I've now removed the /dev/null line so I receive e-mail notifications and I'm getting the following error message:
/bin/sh: php: Permission denied
What I don't understand is why permission is being denied on this command but not on the other two...
Not sure what could have happened, but first thing I would do is to check if the permissions for the new php script are the same as what the old ones have. Do a ls -l on both httpdocs/forum/notifyreply.php and httpdocs/forum/notifytopic.php, and compare the permissions against what httpdocs/crm/autoMessages/autoEmail.php have.
You are not setting a User/Group for the cron command, better do it like this
* * * * * www-data www-data php -q httpdocs/crm/autoMessages/autoEmail.php > /dev/null 2>&1
(assuming that www-data is the correct User)
note that I put the error handling at the end.
Also, I think that you should use the full path; either you forgot to add a slash ( /httpdocs/.... ) , or do you have this script in the cron folder?

Status: 301 Moved Permanently ActiveCollab

I tried to set cronjob on my server for ActiveCollab
I use this
*/5 * * * * php "/home/bbb/public_html/tasks/frequently.php" RnuFA > /dev/null
but it always returns error message :
Status: 301 Moved Permanently
Location: https://mywebsite.com/
Content-type: text/html
I've tried to execute the command through SSH and it worked properly.
Can someone help me telling what configuration on my server that need to be checked for this kind of issue?
Thank you
Official recommendation is to use cURL to trigger scheduled tasks, not executable PHP. Currently it is just a recommendation, but upcoming releases will stop shipping /tasks folder so you will have to use cURL.
There are many environments (more than we expected) where there is one PHP that web server uses to prepare the page, and another PHP that runs via command line interface (CLI). This causes all sort of problems, so we decided to use only way way of triggering tasks - via URL.
Bottom line - use cURL. Documentation is here:
https://activecollab.com/help/books/self-hosted-edition/scheduled-tasks-setup.html
Here are sample commands:
*/3 * * * * /usr/bin/curl -s -L "http://url/of/frequently?code=XyZty" > /dev/null
0 * * * * /usr/bin/curl -s -L "http://url/of/hourly?code=XyZty" > /dev/null
0 12 * * * /usr/bin/curl -s -L "http://url/of/daily?code=XyZty" > /dev/null
0 7 * * * /usr/bin/curl -s -L "http://url/of/paper?code=XyZty" > /dev/null
but make sure to check Administration > Scheduled Tasks page of your activeCollab for exact URLs that you need to trigger.

Cron job: problem with crontab, it automatically sending me an email

How can I disable the email on the cron?
Send the standard output (and standard error) of your cron job to /dev/null
* * * * * /some/cron/job 1> /dev/null 2>&1
If you'd prefer a log file, change /dev/null to a real filename instead, but be aware of the security issues. Specifically, if you're running with any sort of privileged account and the log file doesn't already exist, a hacker can pre-create a symlink in place of your log file, pointing at some other file. When your cron job runs the target of the symlink gets overwritten.
You can redirect the output to /dev/null like this:
* * * * * my_command > /dev/null
If an error occurs, you'll still get an email, though.

Resources