1

I have this in my crontab:

* * * * * /Applications/MAMP/bin/php/php7.2.10/bin/php -f /Users/user/Documents/radio_bycron.php 2>&1 > /Users/user/Documents/radio_bycron.php_output.txt

In /Users/user/Documents/radio_bycron.php_output.txt, there's only one line which is:

Could not open input file: /Users/user/Documents/radio_bycron.php

I have already chmod 0777 the script /Users/user/Documents/radio_bycron.php, but I am still getting this issue. The problem happens with or without the -f flag.

If I execute the command directly on the Terminal, it works perfectly.

How can I solve this problem?

1
  • 2
    This is caused by TCC, which restricts access to the Documents folder, among others, at the kernel level. A process must be able to prompt the user interactively for permission to access those folders. Try moving the file you want to read out of Documents to a new subfolder of your home directory.
    – Linc Davis
    Commented Jul 25 at 17:30

1 Answer 1

0

You might try this:

* * * * * /Applications/MAMP/bin/php/php7.2.10/bin/php -f /Users/user/Documents/radio_bycron.php >> /Users/user/Documents/radio_bycron.php_output.txt 2>&1

I'm not familiar w/ PHP, but I read the (as revised above) cron job as follows:

  • every minute:

  • use the php interpreter: /Applications/MAMP/bin/php/php7.2.10/bin/php

  • with the -f option (read file??)

  • to run the contents of the file: /Users/user/Documents/radio_bycron.php

  • and redirect (>>, do not overwrite) the output (stdout) of the radio_bycron.php script to the file /Users/user/Documents/radio_bycron.php_output.txt

  • and also redirect 2>&1; i.e. send stderr (2) to stdout (1) (effectively capturing both stderr and stdout in the file /Users/user/Documents/radio_bycron.php_output.txt)

My changes were prompted by two potential problems in your version of the cron job:

  1. redirection to the file (>) should occur before the 2>&1 redirect
  2. as you execute every minute, the overwrite form of the redirect (>) may be overwriting earlier output - which might be more meaningful); ergo, use the augment form of redirect (>>) to capture everything.

Finally, your crontab entry says you're executing the command every minute... that might be a problem if more than 1 minute is required to complete the script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .