I have a cakephp shell that works correctly. If I run
/Users/petarpetrov/path_to/app/Console/cake CleanDatabase
it works great. However, as per documentation if I try this:
* * * * * cd /Users/petarpetrov/path_to/app && Console/cake CleanDatabase
I get the error:
-bash: Config: command not found
I noticed that it does matter where I am at the point of issuing the crontab command. If I run it from / I would get:
-bash: Applications: command not found
So I have really no idea what is going on. Any help?
Task code:
<?php
class CleanDatabaseShell extends AppShell {
public function main() {
$this->out('hello');
}
}
I figured it out. I was pasting this line in terminal which was wrong:
* * * * * cd /Users/petarpetrov/path_to/app && Console/cake CleanDatabase
when in fact I should have done:
crontab -e to open the editor
paste the line in
save & close it.
Related
So i have this php function path in codeigniter which I am trying to run through cron job in ubuntu. But whatever I have tried it is not working. The command I have tried so far
* * * * * /usr/bin/php http://localhost/QAPIv2/updateTestData
But it is not executing. I am using codeigniter
To elaborate on Rohan's answer, you run the functions like php index.php controller function. So, for example, to run your script every Tuesday at 8:31AM, your crontab entry should look like :
31 08 * * 2 cd /path/to/codeigniter; /usr/bin/php index.php QAPIv2 updateTestData;
Try this:
*/1 * * * * /usr/bin/php /var/www/html/YOUR PROJECT FOLDER NAME/index.php YOUR FUNCTION NAME > /dev/null 2>&1
First number is time for cron.In function name you should give the controller function name which you want to load in cron.
Please call the function from the command line.
$ cd /path/to/project;
$ php index.php controller function
Please change the controller and function according to your code.
I have the following method in my Kernel.php (the one under Console of course):
protected function schedule(Schedule $schedule)
{
$schedule->exec("touch lorem.txt")->everyMinute();
}
And I have the following cronjob added through the cpanel:
* * * * * cd /home/oeit/oe && php artisan schedule:run >> /dev/null 2>&1
I am supposed to see a lorem.txt file in the disk. However when I search for it using find / -name "lorem.txt" the file doesn't appear, which makes me believe that my cronjob is not working properly. I am on a shared hosting.
How do I fix this?
I had to specify the full path for the php executable:
* * * * * cd /home/oeit/oe && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
If you're on shared hosting, it's entirely possible that it is running, but you don't have access to use $schedule->exec on the server.
I would take a look in the storage/logs/laravel.log file to see if you are getting any errors.
I have this simple command in symfony :
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AuctionEndCommand extends Command
{
protected function configure()
{
error_log(print_r('test',true), 3, "/tmp/error.log");
$this->setName('desktop:auction_end')->setDescription('Execute when auction is end.')->setHelp("Identify winners for auctions");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// outputs multiple lines to the console (adding "\n" at the end of each line)
$output->writeln([
'User Creator',
'============',
'',
]);
// outputs a message followed by a "\n"
$output->writeln('Whoa!');
// outputs a message without adding a "\n" at the end of the line
$output->write('You are about to ');
$output->write('create a user.');
}
}
Now when I execute : /var/www/myProject/bin/console desktop:auction_end this command works fine. But when I try to execute as a cron in linux this script doesn't start :
In linux as sudo I did :
nano crontab -e, and the cron :
* * * * * /usr/bin/php /var/www/myProject/bin/console desktop:auction_end > /dev/null
What I'm doing wrong, can you help me please ? Thx in advance and sorry for my english
I can keep it very short. You will need to use PHP to execute the console.
* * * * * php -q /usr/bin/php /var/www/myProject/bin/console desktop:auction_end > /dev/null
Writing the output of a cron job that you are testing to a file will help you debug errors. All output is now lost in the void :)
* * * * * php -q /usr/bin/php /var/www/myProject/bin/console desktop:auction_end > /home/<user>/crons/auction_end.cron.txt
Edit
It might be that your php should be used as absolute path.
* * * * * /path/to/php /path/to/bin/console symfony:command
Or even by specifying the user to execute the command with:
* * * * * root /usr/bin/php /path/to/bin/console command:to:execute
Also make sure that the root user has permission to execute files in your symfony project.
What user are you executing the cron as?
Symfony requires write access to ( depending on version ) app/cache && app/log(s) || var/cache && var/log(s) if the user you're executing the command as doesn't have write access to the directories you're trying to write to then your operation will fail.
A good way of fixing this would be to check the error logs, either in var/log(s) app/log(s) or check the apache2 error logs in /var/log/apache2/error.log I would guess one of these logs will contain a hint to your problem.
If you run it as root, does that work:
* * * * * root php /var/www/myProject/bin/console desktop:auction_end > /dev/null
See if that works.
On CentOS release 6.5 (Final):
I know that usually I just need to use the following command in crontab to run a php script.
0 * * * * /usr/local/bin/php absolute_path_file_to_the_script.php
But, recently, it stopped working. The only work around is to use the following command
0 * * * * /usr/local/bin/php absolute_path_file_to_the_script.php > log
But I would rather not to output anything to log for now.
So, I even tried
0 * * * * /bin/sh -c "/usr/local/bin/php absolute_path_file_to_the_script.php"
But the above commend is again not working in crontab (it works if I type in the shell directly).
And I am sure that the above command did run in crontab for a second with
ps ux, and then it stopped executing.
Any ideas on how to run the command properly without logging?
Try run that command (only php, without cron settings) from terminal and show result
Both answers from Marc and Greg work:
> /dev/null
or
> /dev/null 2>&1
I have created a php yiic command as
class StartCommand extends CConsoleCommand {
public function run($params){
Yii::log("Cron Job has started");
}
}
When I run the command php yiic Start, I get the result in the log.
And I have add this to the crontab
* * * * * /usr/bin/php /path/app/console/commands/StartCommand.php
But the job is not running.
I think I have to mention the php yiic Start to the crontab.
But where do I add it ??
* * * * * cd /path/app/console/commands && php yiic Start