I need script Copy permissions of files and folders from one server to another

Hi..
I have 2 servers with linux suse10.

I made a mistake and on one of the servers changed with chmod the permission of root in directory /.
In the other servers the permissions are correct

Please i need a script, to change the permissions of one server 1, using the same permission of the other server 2...

Hi.

Not sure if this is so great, but based on this thread: ls to show numeric permission bit ...

Run this on the server with the good permissions:

find / -type f -o -type d 2>/dev/null | while read FILE; do
  perl -le'
    printf "chmod %o \"%s\"\n", 07777 & (stat)[2], $_
    for @ARGV
  ' "$FILE"
done > /tmp/file_perms.sh

Copy and run /tmp/file_perms.sh on the server with the "bad" permissions.

Good luck :slight_smile:

1 Like

thanks for all..
But.. how execute chmod with the file?

Were you logged in as "root"?
What directory were you in at the time?
What did you type?

1 Like

:eek:

Good questions.

I might have made a bit of an assumption. Forget the script!

But there shouldn't be too many files in / itself, so I was guessing it was bad :slight_smile:

1 Like

The user root.

and the directorys. i have in a file generate with this script.

i start the chmod in /

What was the current working directory at the time? Was it "/" or "/root" or some other directory?

What did you actually type?
Or if this is a script, what is in the script?

Do commands on the server still work?

1 Like

The directory when i can run the scrip is in "/" with all directoris.

my answer is.. what is the comand chmod.. to run with a file_perms.sh

---------- Post updated at 04:53 PM ---------- Previous update was at 04:40 PM ----------

i repittt...

i work in /

Hi,

If both the servers were identical prior to change ,then on the server thats good run the following

find / -type -printf "%h/%f %m\n" >> /root/do-restore.sh

Then copy the /root/do-restore.sh to the server you have accidentally changed the permissions , I would say a quick way would be cat the file ,run a while loop and do chmod something like

cat /root/do-restore.sh|while read IN
do
fn=`echo $IN|awk '{print $1}'`
per=`echo $IN|awk '{print $2}'`
chmod $per $fn
done
2 Likes

A nice Linux option :slight_smile: Thanks!

If you run it this way, then you can just copy the file to the target and run it...

find / -type f -o -type d -printf "chmod %m %h/%f\n" > /root/do-restore.sh
1 Like

Until we find out what the O/P actually typed I'd be wary of doing a blunt permissions change from root.
Knowing what was actually typed would help cut the list down because we could no doubt compose a "find ..... -perm ..." statement.

The script posted above will misbehave with filenames containg space characters. If we introduce a delimiter in the "printf" it would be improved.

Cautious approach would be to run the "find" process on both computers for all inodes (not just files), then sort and compare the two listings to see what we are up against. Even on similar systems I would expect differences which must be ignored.

1 Like

I use the script and are tot ok...

very tnaks for allll...

regards