Laravel crontab -e is not recognized

This is my first time setting up Cron job and I cannot make it to automatically schedule a command.

So I have a command:

public function handle()
{
    $client = new Client();
$crawler = $client->request('GET', 'http://www.oldham-chronicle.co.uk/news-features');
$crawler->filter('div[id=content]>.homefeature')->each(function ($node, $key) {
    $title = $node->filter('.plain')->text();
    $datepublished = $node->filter('.dateonline')->text();
    $description = $node->filter('.teaser-link')->text();
    $link = $node->filter('a')->link();
    $link_r = $link->getUri();
    $image = $node->filter('img')->image();
    $image_s = $image->getUri();
    $filename = basename($image_s);
    $image_path = ('news-gallery/' . $filename);
    Image::make($image_s)->save(public_path('news-gallery/' . $filename));
    $id = 1+ $key + 1;
    $news = News::where('id', $id)->first();
    // if news is null
    if (!$news) {
        $news = new News();
    }
    $news->title = $title;
    $news->datepublished = $datepublished;
    $news->description = $description;
    $news->link = $link_r;
    $news->image = $image_path;
    $news->save();
});
$crawler->filter('div[id=content]>.teaser-50')->each(function ($node, $key) {
    $title = $node->filter('.plain')->text();
    $datepublished = $node->filter('.dateonline')->text();
    $description = $node->filter('.teaser-link')->text();
    $link = $node->filter('a')->link();
    $link_r = $link->getUri();
    $image = $node->filter('img')->image();
    $image_s = $image->getUri();
    $filename = basename($image_s);
    $image_path = ('news-gallery/' . $filename);
    Image::make($image_s)->save(public_path('news-gallery/' . $filename));
    $id = 1+ $key + 1;
    $news = News::where('id', $id)->first();
    // if news is null
    if (!$news) {
        $news = new News();
    }
    $news->title = $title;
    $news->datepublished = $datepublished;
    $news->description = $description;
    $news->link = $link_r;
    $news->image = $image_path;
    $news->save();
    $this->info('Scraping done succesfully');
});
}

Kernel file:
protected $commands = [
    'AppConsoleCommandsNewsScrape'
];

/**
 * Define the application's command schedule.
 *
 * @param  IlluminateConsoleSchedulingSchedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('scrape:news')
             ->hourly();
}

And I go to a project folder, type crontab -e and I get:

‘crontab’ is not recognized as an internal or external command,
operable program or batch file.

How can this be solved? Please, remember it is my first time using it

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In production you must set up the following crontab:

Docs: https://laravel.com/docs/5.4/scheduling

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

Be sure to update /path-to-your-project/ as appropriate.

This will run the php artisan schedule:run command every minute which will check to see if any schedulers need running.

I do not know how to set this up for Windows, however I suggest using the development environment Homestead, which uses Vagrant and Virtual Box. It will provide you with a Ubuntu VM, so you can use crontab.

Method 2

there is no crontab command on windows, this would work or your production environment but not on windows.

the equivalent is at in command line, type at /? to have some help with it, i can’t help you with this as i never used it


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x