When this is run from /etc/crontab:
* * * * * root cd ~admin; mkdir test
* * * * * root cd ~admin; chown root test
* * * * * root cd ~admin; chgrp admin test
* * * * * root cd ~admin; chmod 777 test
only the first command works.
When i put these into a script and run it via command
line, all 4 work fine. I remember having used
crontab to do permission before, so I'm not sure what
the story is.
That is because you are telling Cron to run all these command at the same moment. Ok your choices are 1:
Code:
*/5 * * * * root cd ~admin; mkdir test
1,6,11,16,21,26,31,36,41,46,51,56 * * * * root cd ~admin; chown root test
2,7,12,17,22,27,32,37,42,47,52,57 * * * * root cd ~admin; chgrp admin test
3,8,13,18,23,28,33,38,43,48,53,58 * * * * root cd ~admin; chmod 777 test
(my use of progressions are not what they used to be so that is what I can come up with this early in the day)
#2: You could put them into a script which would work fine
or
#3: you could append them together like this
Code:
* * * * * root cd ~admin; mkdir test;chown root test;chgrp admin test;chmod 777 test
That is all one line or you could replace the semi-colons with double amersands '&&' which says that if the previous command exited without an error then do the next one (Like this)
Code:
* * * * * root cd ~admin && mkdir test && chown root test && chgrp admin test && chmod 777 test
again that is all on one line. That would be probably the safest without a script. I would recommend #2. Do use a script whyere you can as you can ensure that one step did work before another and then if someting fails you can recover back to earlier steps if necessary. You do not need to create a .sh file but can run the script from one line. This could be an example of the first part..
Code:
cd ~admin ; if [ -d test ];then ;else mkdir test;fi
and while this is a full script it does not need to be in a script file.
Peter
PowerMac G5 Dual 2.5Ghz Mac OS X (10.4.3) Server