Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a folder in the home directory of my server named stock, as /home/stock. In this folder an ftp dump of data is being done by a third party application. The files added to these folders have a permission 644 and ownership as stock.users.

I also have a cron script which needs to access those files, uncompress it and then take further actions. My cron will run as web.users.

The problem is that my script is unable to access the files because of its permission set as 644. Is there any way to permanently set the folder's permission to 664. Executing the command chmod 664 on that folder, just changes the contents of the folder at that point of time but the files dumped in the future date still has permissions as 644.

Its also not feasible to change the permissions of the folder manually and setting a cron job to do the work doesn't seems a good option either.

Can anyone help ?

Thanks in advance.

share|improve this question

migrated from stackoverflow.com Sep 2 '09 at 15:14

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers

It sounds from your description that the cron job just needs to read the files, which it should be able to do. Is the issue that you're trying to uncompress the files in place? Can you uncompress them to a temporary folder instead?

In order to modify the permissions of new files uploaded by FTP, you would need to change the umask of the FTP daemon process to 002. How to do that depends on the FTP server and Linux distribution.

share|improve this answer
add comment

Make the directory owned by the web user, and group writable by the ftp user. Set the setuid bit on the directory, so that all files therein will be owned by the user running the cron job.

share|improve this answer
add comment

Your script could do sudo chmod 664 given that you moddify /etc/sudoers to allow the execution of chmod by web.users without password.

You can do that adding this to /etc/sudoers

web.users localhost = (root) chmod


Edit

Be aware that this in the present way is insecure you have to addapt it to your needs and make sure its secure before doing something like this. One recommendation would be to have a special user for your script.

share|improve this answer
    
This would be really dangerous from a security point of view - if the 'web' account were compromised (hit something unexpected in the subsequent processing) it would be able to run chmod on anything –  Novelocrat Sep 2 '09 at 14:16
add comment

you can also add this chmod line in you script (run it as root OR (safier) the user who is used for the ftp transfers) :

#!/bin/sh
chmod -R 664 /home/stock
tar -zxvf /home/stock/file.tar.gz for instance
+ treatments
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.