I have a dir in a server, that receives files with the wrong permissions, so I decide to put on a cron entry that changes its permitions, but because of the time gap, not all of them get changed.
What I did was the following:
If the user account is only for delivering files and it fits to your environment, you could set a umask of 111 for this user to have all files with the same permissions that are created.
If you tend to use the cronjob, maybe just use another * instead of all these comma separated minutes. Have the output redirected to /dev/null to not spam your logs, ie. something like this:
It could be you will need absolute paths to find and chmod etc. or maybe just put it into a little script (I personally prefer that) and call this script via cron.
Depending on how the files are deliviered, maybe you can set a umask with the file transfer tool you are using.
As said, better put it into a script and have the paths to find and as absolute paths.
You can try to add the ftp command
site umask 111
when sending the file to have it the correct permissions. You can also have the ftpd a default umask in /etc/inetd.conf, but that will be for all transfers then.
Also you might want to think using scp/sftp if possible, since ftp is not encrypted.
I need to chmod all files arriving in a landing directory every moment and them moved them with the new permissions to another directory.
I came up with the following code, please help:
#!/usr/bin/sh
a=`find /temp/in_ccn -type f ! -perm a+rw -exec chmod a+rw {} \;`
for i in $a ; do
mv /temp/in_ccn/$i /final_destination/dir
done
If a file is already available, it will be replaced when you use mv command.
If you still want to check and delete if the file already exists at destination,
for i in /temp/in_ccn/*
do
if [[ ! -f /final_destination/dir/${i} ]]; then
chmod a+rw /temp/in_ccn/${i}
mv /temp/in_ccn/${i} /final_destination/dir/
else
rm /temp/in_ccn/${i}
fi
done
#!/usr/bin/sh
for i in /var/tmp/temp/in_ccn/*
do
/usr/bin/chmod a+rw /var/tmp/temp/in_ccn/${i}
/usr/bin/mv /var/tmp/temp/in_ccn/${i} /final_destinat/in_ccn/
done