Question

I have written a custom command that has 1 argument which is the current time (in string format)

artisan check-banners $(date +%X)

The argument is then passed to the fire method and I can successfully insert the current time into the database. However... when i try to cronjob this custom command it does not work. see code below:

* * * * * php /Applications/AMPPS/www/laravel/artisan check-banners $(date +%X)

I have tried insert 'foo'instead of $(date +%X) as an argument and it successfully inserts into the database.

Why can't I insert this $(date +%X) through the cronjob?? But I can manually type it via artisan check-banner $(date +%X) and it works

Many thanks.

Was it helpful?

Solution

Percentage signs have special meaning in crontab and need to be escaped, like so:

* * * * * php /Applications/AMPPS/www/laravel/artisan check-banners $(date +\%X)

Also, I'm not sure, but you may need to wrap the +%X argument in quotes as well:

* * * * * php /Applications/AMPPS/www/laravel/artisan check-banners $(date "+\%X")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top