Re: script to change permissions of incoming files (236 Views)
Reply
Super Advisor
NDO
Posts: 531
Registered: ‎12-10-2003
Message 1 of 6 (256 Views)
Accepted Solution

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

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,753
Registered: ‎03-06-2006
Message 2 of 6 (251 Views)

Re: script to change permissions of incoming files

[ Edited ]

>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}')

 

 

Please use plain text.
Valued Contributor
Ralf Seefeldt
Posts: 166
Registered: ‎04-02-2001
Message 3 of 6 (248 Views)

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

Please use plain text.
Super Advisor
NDO
Posts: 531
Registered: ‎12-10-2003
Message 4 of 6 (246 Views)

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

 

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,753
Registered: ‎03-06-2006
Message 5 of 6 (236 Views)

Re: script to change permissions of incoming files

[ Edited ]

>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 {} +

Please use plain text.
Super Advisor
NDO
Posts: 531
Registered: ‎12-10-2003
Message 6 of 6 (211 Views)

Re: script to change permissions of incoming files

 

Hi

 

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

 

 

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation