Laravel4 task to cron - laravel

I'm trying to create a cron using a task I made. The problem is I have no clue how to build the cron. My task name is meeting:close, and it's in my commands folder.
Can anyone help me to build the url to call this task every hour? I guess it will start with 0 * * * *
Thanks everyone!

To create a cronjob, you have to edit a file. It is pretty easy, run crontab -e to edit the cron file for the current user.
Now just add a line to the file that opens:
0 * * * * php /full/path/to/your/application/artisan meeting:close
Maybe you also have to specify the absolute path to your php executable
Now save the file and you're all set.
By the way, if you didn't know, you can run your commands with php artisan command:name from the terminal (that's also what the cronjob is going to do...)

Related

Laravel not executing scheduled command

I'm using laravel telescope. I used the following code to schedule the prune command in kernel.php (it has 48 hours but I already tried with less hours):
$schedule->command('telescope:prune --hours=48')->daily();
I tested it in my local environment and it prunes the data correctly. But once in my production server it doesn't seem to be working.
Telescope is runing there and capturing data. I thought it could be a telescope command issue, but I ran
php artisan telescope:prune
and it works, it says "25404 entries pruned", I also verified this in the DB. Also, my cron task is runing every minute, and I have some scheduled calls like this:
$schedule->call('*some irrelevant stuff*')->cron('0 */3 * * *');
$schedule->call('*some irrelevant stuff*')->dailyAt('00:00');
And they are working as expected. I also tried calling the scheduller manually inside a function:
Artisan::call('schedule:run');
and the schedule calls work, but "$schedule->command" does not.
So, I'm guessing that the problem is that somehow "$schedule->command" is not working. Do you have any idea or suggestion to fix this?
You should set Laravel Task Scheduler to your's servers crontab file, adding the following entry:
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1

Laravel Schedule creates a file for every call to a command

I have created a schedule with Laravel and after some struggle I managed to get it working but the problem now is that for every call to the a command it creates a file inside the laravel folder and they are getting pilled up.
I am using this command at the crontab to keep it running:
* * * * * /usr/local/bin/php path/to/artisan schedule:run >> /dev/null 2>&1
I guess I need to use some options to prevent it from output. Any idea?

Status of cron job

I have written a cron job as follows:
$crontab -e
Then it opened a file where i wrote
5 * * * * USERNAME PATH-TO-SHELLSCRIPT
How would i come to know that my job has been executed?
Do something with the script? Edit a file and add timestamp for example to see if its ok :)
You can use a log file. Create a file under your home directory, e.g., "/home/user/.cronlog/script1", and output script execution time and status messages with timestamps. You can then check the logs to see script history. To test your script first execute it every minute. Then change the crontab entry to the actual period.
Also make sure you understand the time parameters so you know when to expect it to work :)
I use crontab for a 5 min interval cron like this: */5 * * * *
http://en.wikipedia.org/wiki/Cron

Bash Script with Crontab

I'm trying to setup a crontab I have this in my current job in the current user I'm logged into
* * * * * /CS/day/get_info.sh
get_info.sh is supposed to output a text file every minute and I suspected that it would output a file in the same directory as the script is located but it doesn't.
I've also checked the syslogs to see if I could figure this out.
(user) CMD (/CS/day/get_info.sh)
(user) MAIL (mailed 46 bytes of output but got status 0x0001#012)
Can someone explain to me why this is happening?
Thanks
man cron tells you:
When executing commands, any output is mailed to the owner of the
crontab (or to the user named in the MAILTO environment variable in the
crontab, if such exists). The children copies of cron running these
processes have their name coerced to uppercase, as will be seen in the
syslog and ps output.
So you have to
cd into the appropriate directory yourself (cron will use $HOME)
redirect ANY output to a file of your choice
You can do both things in the crontab. But I recommend to do it in the first lines of the script itself:
#!/bin/bash
cd WHEREEVER_YOU_WANT
exec > YOUR_LOG_FILE 2&>1
The script is run in the home directory of the user and the file should be there as well. If you want it in the same directory as the script, either do a cd in your script or modify your crontab entry:
*/1 19-20 * * * cd /CS/day; /CS/day/get_info.sh
Another common problem with crontab entries is the environment. If the script works correctly in your terminal, try debugging it, when it is run from cron:
40 11 * * * bash -x /CS/day/get_info.sh >/tmp/get_info.sh.log 2>&1
Run it once only with current time, because otherwise you will overwrite your log file every minute.
On my case, I just had to install and configure an smtp client.

crontab is not running my script

I'm new to cron jobs. I read a post on how to write a cron job with crontab.
So my crontab looks like this:
1 * * * * /Users/apple/Desktop/wget/down.sh
which basically means that every minute i want to execute the script :down.sh. Now the script runs
fine manually. The script is a simple program that downloads a PDF from the internet:
#!/bin/bash
wget -U Mozilla -t 1 -nd -A pdf "http://www.fi.usj.edu.lb/images/stories/HoraireS08/3eli.pdf" -e robots=off;
I don't know why it's not running every minute once the terminal tells me that he's installing the new crontab.
Can somebody help me please?
Solution:
Thank you all for your help, the syntax as mcalex said should be
* */1 * * * path/to/script
if you want it to be executed every hour.
The cron job was working normally.However my mistake was simply writing permissions, in fact while executing the wget command, it's supposed to write the pdf file in the current workind directory which is a system directory in case of the cron tab. so i solved my problem simply by navigating to the Desktop directory before executing the wget command like so:
cd /Users/apple/Desktop/wget
and then do whatever i want to do.
PS: i should include the full path of the wget command too.
Thank you all for you help again:)
When you put 1 in the first column, it will run on the first minute (of every hour). In order to get it to run in every minute of every hour, you need to set the minute column as */1
So your line should read:
*/1 * * * * /Users/apple/Desktop/wget/down.sh
supporting links:
job every minute: https://bbs.archlinux.org/viewtopic.php?id=59180
job every 5 minutes: http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/
1 * * * * /Users/apple/Destop/wget/down.sh
From this entry script will never run on every minute because it will run on first minute of every hour.
Make this change to your crontab file to run this script every min.
"* * * * * /Users/apple/Destop/wget/down.sh"
Do you have a typo? It looks like you might have mis-typed Desktop?
Another thing to do is to redirect the output of running the script to a file so you can see what's going on like this:
1 * * * * /Users/apple/Destop/wget/down.sh >> /tmp/cron.out
and then check out the file to see what's going on.
Did cron send you some email detailing what went wrong?
Does the script under that path exist?
Note that cron uses /bin/sh to execute commands.
Did you set a proper PATH in your script? wget may not be in the default PATH or there may be no PATH at all. Try using /path/to/wget in the script.
Note that downloading the same PDF file once a minute is probably a silly idea, though...
If your cronjob is writing things to disk then be careful that system preference "Put hard disk to sleep when possible" is unchecked.
This was preventing my cronjob backup tasks to execute.

Resources