Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

binish's avatar

Setting up Larvel Cron

Hi,

Please provide us a step by step solution for setting up the cron job. We have tried in too many ways but nothing working fine. ( Server is Linux based)

The Step we followed are listed below,

  1. Created a controller and function
  2. added the line of code in Console/Kernal.php $schedule->call('PushController@sendTanglePush')->cron('* * * * * *');
  3. And in root/crontab.txt file added with following lines of code

MAILTO=tester@gmail.net
30 11 * * * php /var/www_testing/testin.php >/dev/null
* * * * * php /var/www_testing/artisan schedule:run 1>> /dev/null 2>&1

4.Then, after setting the cron job using linux command, it shows the following errors as mail

/bin/sh: 1 : ambiguous redirect

Note: the cron is not able to call PushController@sendTanglePush action, what is exact step to setup a cron in laravel

0 likes
6 replies
phred's avatar

Hey @binish, can you clean up the formatting on your cron you posted in step #3? You might have a syntax problem with one of your jobs.

I think it should look like this:

MAILTO=tester@gmail.net
30 11 * * * php /var/www_testing/testin.php > /dev/null
* * * * * * php /var/www_testing/artisan schedule:run 1>> /dev/null 2>&1

Notes:

  1. Cron lines always have 6 fields at the start specifying how often to run. You probably know that, but just make sure you have 6 on each line. The fields are minute hour day-of-month month day-of-week. Everything after that is treated as a sh command. man 5 crontab if you want to read up more on that.
  2. You must have a blank line at the end of the crontab or the last job will get ignored.

Since your error is coming from sh I'd try running the each line's command by hand. If you post a code block with your cron tab we can probably help more. Click the "GitHub-flavored" link below to see how. You could also create a Gist and paste a link here.

Hope that helps!

binish's avatar

Hey @phred , thank you for your quick reply, actually the cron is working fine. My problem is the laravel based cron ie,


* * * * * * php /var/www_testing/artisan schedule:run 1>> /dev/null 2>&1

is not triggerring.

But the simple php script set as cron is working fine.


30 11 * * * php /var/www_testing/testin.php > /dev/null

As you said we already tried with a blank space after the crontab.txt file, but this has also no effect, showing the same error.


/bin/sh: 1 : ambiguous redirect

jimmck's avatar

Set your SHELL and PATH in cron file. Here is mine for example. (Make sure to edit for your setup!!)

SHELL=/bin/bash PATH=/Applications/:/Applications/XAMPP/xamppfiles/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

          • php /Users/jimm/WebProjects/laravel42/artisan scheduled:run 1>> /dev/null 2>&1
jimmck's avatar

Opps..

SHELL=/bin/bash
PATH=/Applications/:/Applications/XAMPP/xamppfiles/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
* * * * * php /Users/jimm/WebProjects/laravel42/artisan scheduled:run 1>> /dev/null 2>&1
phred's avatar

Can you check the line endings on your cron file and repair them as directed in this post?

Also, how are you editing your crontabs? crontab -e ?

Please or to participate in this conversation.