chown doesn't work in cron

i need a script to run every hour. the script changes some files' permissions, and i've tested the script manually to make sure that it works. i then include it in the root's crontab. everything works fine, except the lines where i use chown to change the permissions. those few lines just don't seem to be executed.

so here is what i did to debug this situation. i have a script called myscript.sh that contains the following lines:

#!/bin/sh
logpath="/Library/Logs/ssh_fix.log"
if [ `id -u` -ne 0 ]; then
echo "Error: Not super user." >> "$logpath"
echo `date`": Exit script, status 1." >> "$logpath"
exit 1
fi
chown -v root:wheel ~/Desktop/test.txt
echo `date`": Exit script, status 0" >> "$logpath"
exit 0

the script is set to be executable, and it works fine byitself. but when i put it in the crontab, chown doesn't do a thing. and as you can see, i do a test first to see if the script is run as a super user, which it was.

am i missing something? is there something between chown and cron that don't mix well? i'd appreciate any reply. thanks.

PowerBook G4, Mac OS X (10.5.7)

Posted on Jul 15, 2009 6:39 PM

Reply
9 replies

Jul 15, 2009 8:00 PM in response to TsW Mac


chown -v root:wheel ~/Desktop/test.txt

are you running this as 'root'? That is to say, did you invoke this script from the root's crontab file?

What does your crontab entry look like? Does it look something like:

sudo crontab -u root -l
0 * * * * /path/to/myscript.sh

And is ~/Desktop, the root's Desktop, or is this your Desktop? This would depend on who is running the script.

Message was edited by: BobHarris

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

chown doesn't work in cron

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.