Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a cron job with arguments and pass results to a log?

Example:

* * * * * /usr/bin/php /full/path/to/script.php arg1 arg2 > /full/path/to/logfile.log

The script runs and accesses the arguments just fine, but the results are never printed to the logfile.log. Also, my logfile.log is chmod 777, so I know it has write access.

Can you fix my syntax?

like image 580
Ryan Avatar asked Oct 22 '11 07:10

Ryan


People also ask

Is there a log for cron jobs?

Stop searching for logs On Ubuntu, Debian and related distributions, you will find cron jobs logs in /var/log/syslog . Your Syslog contains entries from many operating system components and it's helpful to grep to isolate cron-specific messages.

What is the use of * * * * * In cron?

* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.

Can you use variables in crontab?

Setting Each Variable in the crontab File Similar to the BASH_ENV method mentioned before, we can set any variable writing name=value before the command. If we specify more than one variable, we have to space them with whitespaces in between.

What does * 5 * * * mean in cron?

5 * * * * means it runs once per hour at five minutes past the hour. */5 * * * * means it runs once every five minutes.


1 Answers

It looks like you are searching for the log file in the wrong folder. Try this

* * * * * cd /path/to/script.php ; ./script.php arg1 arg2 >> logfile.log

Then look for your log file in the /path/to/script folder. It can also be a write permission problem. Also, check your script for errors. Your crontab command seems OK.

like image 101
mik Avatar answered Sep 30 '22 01:09

mik