Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

script to change permissions of incomming files

SOLVED
Go to solution
NDO
Super Advisor

script to change permissions of incomming files

Hi All

 

I have a system that receives files via ftp from another system and these files arrive at a certain directory, but these files are arriving with

-rw-r--r--

 permissions, but to further process them they need to be change to:

-rwxrwxrwx

 So, I use the following command in the crontab to do the job, but, if the files arrive in large numbers, the permissions do not change:

 

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/chmod 777 $(ls -l /moneta_polled01/sgsn/ | awk '$0 !~ /rwxrwxrwx/ && /^-/{print $9}')

 I even try to shorten the time that entry runns, but no sucess.

 

Please can you help on this?

 

FR

5 REPLIES
Dennis Handly
Acclaimed Contributor

Re: script to change permissions of incoming files

>to further process them they need to be change to:  -rwxrwxrwx

 

Since these files are not scripts you should NOT add execute permission.

 

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/chmod 777 $(ls -l /moneta_polled01/sgsn/ | awk '$0 !~ /rwxrwxrwx/ && /^-/{print $9}')

 

Instead of putting this all in your crontab entry, you may want to create a script where you can easily make changes.

But your immediate problem is that your ls(1) doesn't provide your directory path.

... cd /moneta_polled01/sgsn; chmod a+rw $(ll | awk '$0 !~ /rwxrwxrwx/ && /^-/ {print $9}')

 

 

Ralf Seefeldt
Valued Contributor

Re: script to change permissions of incomming files

Hi,

 

an additional problem may be, that you change the permissions of all files in one big command. Ther is a limit fo files that you can provide to one single chmod command.

 

You better would execute:

 

cd /moneta_polled01/sgsn

for file in `ls -l /moneta_polled01/sgsn/ | awk '$0 !~ /rwxrwxrwx/ && /^-/{print $9}'`

do

  /usr/bin/chmod 777 ${file}

done

 

You can put this in a one-liner, if you want.

 

In addition, as Dennis said, reduce the permission as far as possible, probably changing the groupownership to get rid of those ugly permissions for everybody.

 

Bye

Ralf

NDO
Super Advisor

Re: script to change permissions of incomming files

Hi

 

I wrote a little script but does not seem to be working:

 

mkdir -p /tmp/tmpdir
#find . -exec ls -l {} \; |grep -v rwxrwxrwx |awk '{print $9}' > /tmp/tmpdir/filelist
find /moneta_polled01/sgsn/ -exec ls -l {} \; |grep -v rwxrwxrwx |awk '{print $9}' > /tmp/tmpdir/filelist
cd /tmp/tmpdir
/usr/bin/split -l 1000 fileslist
for i in `ls x*`
 do
  for j in cat $i
   do
    chmod 777 /moneta_polled01/sgsn/$j
   done
 done
rm -rf /tmp/tmpdir

 

Dennis Handly
Acclaimed Contributor
Solution

Re: script to change permissions of incoming files

>but does not seem to be working

 

There is no need to do a split.  And your evil cat has the wrong syntax:

for file in $(< fileslist); do

   chmod a+rw /moneta_polled01/sgsn/$file

done

cd -  # so can remove tmpdir

rm -rf /tmp/tmpdir

 

And it would probably better to use xargs vs your for-loop combination.

Or better yet, only use find:

find  /moneta_polled01/sgsn -type f ! -perm a+rw -exec chmod a+rw {} +

Highlighted
NDO
Super Advisor

Re: script to change permissions of incoming files

 

Hi

 

I have used the find command, on cron, and it looks like is working fine.