Execute Ubuntu command using Laravel Schedule

69 views Asked by At

I want to run a command to remove all files under the folder 'allfiles/'

root@admin:/home/admin/allfiles# find . -name '*' | xargs rm

and it clears all files under allfiles

I want to run the same command using Laravel Schedule, I am using in this way

protected function schedule(Schedule $schedule)
{

    $schedule->exec('find . -name '*' | xargs rm /home/admin/millionfiles/')
             ->everyMinute(); 
}

But it does not work

1

There are 1 answers

0
Aashish Kumar Jaiswal On BEST ANSWER

You missed ' before the directory beginning

Also try adding double quotes instead of single

protected function schedule(Schedule $schedule)  {
    $schedule-> exec('find . -name "*" | xargs rm ' . '/home/admin/millionfiles/')
             ->everyMinute(); 
}