I can see that yes, when i run cron it's in a
different environment, but which one?
It uses the
root environment. When you use
sudo -s, you're getting root privileges, but keeping your regular login environment. If you want to truly become "root" with all the , you'll need to use
sudo su -. That'll give you root's environment.
The simplest way to add an environment variable to a crontab is to just stick it at the top of the crontab. I always add my email address to my crontabs:
MAILTO='username@address.com'
That makes it easier to control where I get the email sent if there's output of some kind. You can also add the usual ".bashrc" and ".bash_profile" files to root's home directory at
/var/root, but I'm not certain how to make
cron see those without rebooting the computer. Read the
bash man pages, particularly the invocation section for more information.
When I run it from the crontab, several, but not all
subfolders have had thier USER permissions changed to
"system" and I cannot access them.
How do I get around that?
Try using the
-p switch with
cp. That's alleged by the
cp man page to preserve user ID, permissions, mod time, etc.
charlie