Crontab Question
Walter Cramer
wfc at mintsol.com
Wed Apr 10 21:40:49 UTC 2019
On Wed, 10 Apr 2019, Software Info wrote:
> OK. So although the script is located in my home directory, it doesnât
> start there? Sorry but I donât quite understand. Could you explain a
> little further please?
Both 'cp' and 'ls' are located in /bin. But if I run the 'ls' command in
/root, 'ls' can't find 'cp' (unless I tell it where to look) - even though
/bin *is* in my PATH -
server7:/root # ls cp
ls: cp: No such file or directory
server7:/root # ls /bin/cp
/bin/cp
Where the system looks for *commands*, to execute, is different from where
it looks for other files, which those commands use. The latter is
generally only the current directory (unless you tell it otherwise).
When cron runs a script as root, "current directory" will be /root.
BUT - for security and other reasons, it would be better to have cron run
your script as you (not root), and as '/home/me/myscript' (instead of
adding your home directory to PATH in /etc/crontab).
-Walter
More information about the freebsd-stable
mailing list