2

I'm running Debian testing and can't get a simple cron to run a symlinked PHP script.

I've a php script in a subdirectory in my home folder /home/foobar/dir/script.php (which starts with the following shebang #!/usr/bin/env php).

I've created a symlink which points to it:

sudo ln -s ~/dir/script.php /usr/local/bin/whatever
ls -la /usr/local/bin
lrwxrwxrwx 1 root staff 24 Feb 27 17:46 whatever -> /home/foobar/dir/script.php*

And added the following rule to my crontab (execute whatever every minute):

crontab -e
* * * * * whatever

But it doesn't work, I get the following error:

cat /var/mail/foobar
...
/bin/sh: 1: whatever: not found

While pointing to the script without using the symlink works:

crontab -e
* * * * * /home/foobar/dir/script.php

Any idea?

Niemand
  • 31
  • 4

2 Answers2

1

Directories like /usr/local/bin and /usr/local/sbin are not by default in cronjobs $PATH. But you can redefine $PATH in crontab, simply put something like this before any defined cronjobs

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Dan
  • 641
  • 4
  • 7
0

The $PATH environment variable under cron is limited, and will include neither /usr/local/bin nor /home/foobar/dir. The correct answer is, as you found, to fully qualify the path to the script in your crontab; it leads to less surprises.

Craig Miskell
  • 4,086
  • 1
  • 15
  • 16