fakesy
1
Hi all
I have this inside a shell script (bash):
cd DIRECTORY
find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' chown -Rv '{}' /DIRECTORY/'{}'
All the directories in this location are named after usernames, so it simply sets the owner to that of the username of the folder.
It works if I run the script manually, but if it is inside a crontab it does not work.
Any ideas?
Many thanks
Have you given the complete path of script instead of just script name in the crontab..? Something like..
0 */2 * * * /full/path/to/test.sh
fakesy
3
Thanks for the reply.
Here it is:
*/1 * * * * root /usr/local/bin/script
It does run fine because when I redirect the output to a text file like:
find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' echo chown -Rv '{}' /DIRECTORY/'{}' > /test.txt
(Note the echo), it populates the text file with all the correct commands.
ctsgnb
4
Don't you miss a dollar sign ?
cd $DIRECTORY
and did you previously set this variable into your script ?
fakesy
5
Apologies I did not paste my code very clearly. That is not a variable, but just a path.
I just found the problem - I did not specify the full paths for all the commands in my script.
Here is the entire working script:
cd /directory
/usr/bin/find . -maxdepth 1 | /usr/bin/sed 's#./##' | /usr/bin/xargs -I '{}' /usr/sbin/chown -Rv '{}' /directory/'{}'