IN a laravel I have a SnapShot method to copy data to a statistics model.
When I run
/var/www/laravel/artisan schedule:run
data are added to the Statistics-table.
Now I have added the following line to /etc/crontab
* * * * * php /var/www/laravel/artisan schedule:run >> dev/null 2>&1
In my /var/log/syslog I read:
Jul 16 08:53:01 cluego CRON[24524]: (root) CMD (cd /usr/bin/php7.4 && php artisan schedule:run /dev/null 2>&1)
Jul 16 08:53:01 cluego CRON[24523]: (CRON) info (No MTA installed, discarding output)
Jul 16 08:54:01 cluego CRON[24599]: (root) CMD (php /var/www/laravel/artisan schedule:run /dev/null 2>&1)
Jul 16 08:54:01 cluego CRON[24598]: (CRON) info (No MTA installed, discarding output)
The laravel.log shows:
[2021-07-16 09:25:01] production.ERROR: No arguments expected for "schedule:run" command, got "/dev/null". {"exception":"[object] (Symfony\\Component\\Console\\Exception\\$
[stacktrace]
when I run manually I get the following result:
root#xxxx:/var/www/laravel# php artisan schedule:run
Running scheduled command: '/usr/bin/php7.4' 'artisan' statistics:snap > '/dev/null' 2>&1
and a data point is added to Statistics-table, just as it is supposed to.
Can anyone see why the cronjob is not running the statistics:snap command, just like the manual schedule:run does?
The problem is that your coron job is wrongly formatted. From the documentation it should look like this:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
So in your case it should look like:
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1
I guess you could also try running your version but with the full path to php instead of only php or using /dev/null instead of dev/null
* * * * * php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1
* * * * * /path/to/php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1
Related
I create a crontab file like this
* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
and a Dockerfile like this
COPY crontab /etc/cron.d/cron
RUN chmod 0644 /etc/cron.d/cron
RUN crontab /etc/cron.d/cron
RUN touch /var/log/cron.log
CMD ["cron", "-f"]
I checked inside container by command service cron status
[ ok ] cron is running.
and crontab -l
* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
All of that look like ok but when I tail -f /var/log/cron.log nothing to happen, how to fix that thank
Since we have upgraded our laravel project from laravel 8 to laravel 9. we are facing issue that all the commands and jobs mentioned in kernel.php are running twice because of which the system is creating duplicate entries in DB. we didn't make any changes to the code.
We also upgraded the ubuntu version from 16 to 20.
I checked the cron file by this command crontab -e but there is a written command only once. maybe on the server from somewhere else ubuntu running one more command as well.
Kernel.php
protected function schedule(Schedule $schedule)
{
//POD STATS update job
$schedule->job(new PodStatsJob)->everyTenMinutes();
//Consignment table backup job
#Pickup Email Reminder
$pickup_reminder_time = substr(getSingleOrganisationSetting("pickup_reminder_time"), 0, 5) ?? '07:00';
// $schedule->command('conveyor:indexing')->dailyAt($conveyor_consignment_indexing);
}
when I check with this command ps aux | grep "artisan schedule:run"
I get this
root 1331614 0.0 0.0 2616 528 ? Ss 15:00 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
root 1331616 0.0 0.9 216924 77220 ? S 15:00 0:03 php artisan schedule:run
root 1345894 0.0 0.0 2616 592 ? Ss 17:39 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
ubuntu 1345895 0.0 0.0 2616 600 ? Ss 17:39 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
root 1345896 27.0 0.9 216924 79020 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345897 28.0 0.9 216924 78944 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345911 0.0 0.0 8484 2428 pts/0 S+ 17:39 0:00 grep --color=auto artisan schedule:run
It seems that two users root and ubuntu are running the same command php artisan schedule:run:
root 1345896 27.0 0.9 216924 79020 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345897 28.0 0.9 216924 78944 ? S 17:39 0:00 php artisan schedule:run
You maybe need to run the service on only one user.
Hello I have enabling the cron feature for Laravel on Ubuntu 18.10 on Vultr VPS server.
I have added the cron task to the cron jobs list using the command
crontab -e
Then I have added the command listed in the laravel documentation
* * * * * cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1
I have made sure that cron is running and I can see that the task is running if I run
sudo grep -i cron /var/log/syslog|tail -3
Which returns
May 20 20:56:01 HiRe-Pro-Web CRON[1819]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
May 20 20:57:01 HiRe-Pro-Web CRON[1862]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
May 20 20:58:01 HiRe-Pro-Web CRON[1898]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
Does anyone have any suggestions where I'm going wrong here.
I am using Laravel and am working with scheduling tasks. It is working fine in one project, but I want to use it in another as well. How would I add the crontab entry needed? Here is what my crontab file looks like for my first project:
* * * * * cd ~/code/project1; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
Here is how I've tried to add the second project:
* * * * * cd ~/code/project1; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
* * * * * cd ~/code/project2; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
and
* * * * * cd ~/code/project1; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1,
* * * * * cd ~/code/project2; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
But neither of these have worked. How would I successfully edit my crontab file for running this command on multiple projects?
I'm trying to run a sh script from crontab. If I run script manually it works perfect, but when I run it in crontab, I get errors.
The script:
#!/bin/bash
sudo tar -zcvf /var/www/nextcloud/data/nextcloud/files/backup.tar.gz /home/beno/stuff/
sudo -u www-data /usr/bin/php /var/www/nextcloud/occ file:scan --all >> /var/www/nextcloud/data/nextcloud/files/backup_log.txt
The script is supposed to make a tar backup of a folder and put it in nextcloud folder and run command files:scan, so nextcloud rescans filesystem and starts synchronization...as I read it here:
https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/occ_command.html#file-operations-label
When crontab runs the script, backup.tar.gz is created, then I get following error:
An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php:60
I'm using ubuntu16 and nextcloud11. Please help!
Following you'r request
Instead of using you'r own crontab, you have to use specic user's crontab, by sudo your crontab command:
sudo -s
then
crontab -e
now you coul add the root's 1st line:
tar -zcvf /var/www/nextcloud/data/nextcloud/files/backup.tar.gz /home/beno/stuff/
and once finished
exit
sudo -s www-data
... and so on...
or (if you could'nt run a shell under www-data):
sudo www-data crontab <<<'01 2 * * * /usr/bin/php /var/www...'
Note: This will overwrite www-data's crontab by this only line!
To prevent this, you could:
sudo www-data crontab -l
to see what contain actual crontab, then
sudo www-data crontab -l |
sed -e '$a 01 2 * * * /usr/bin/php /var/www...'
For adding you'r line, and finally
sudo www-data crontab -l |
sed -e '$a 01 2 * * * /usr/bin/php /var/www...' |
sudo www-data crontab
For replacing actual crontab by modified one.
But it could be simplier to
sudo vi /etc/cron.d/mybackups
Then add you'r rule by following time spec by user name:
21 22 * * * root tar -zcvf /var/w...
22 23 * * * www-data /usr/bin/php /var/www...
Further doc
see man -P'less +/SYSTEM' 5 crontab