Update files in all server

davidd1

Verified User
Joined
Jan 31, 2013
Messages
104
Hello and sorry about my English.

I need help in bash code and i don't know if this is the right forum place:

I have server Centos (linux) with directadmin, and in the server i have 500 accounts.
for all the account (domains) i build my own CMS.

EX: /home/USERNAME/domains/SOMEDOMAIN.COM/public_html/ADMINFOLDER/(*allfiles*)

now i want to update my CMS for all my domain in this server.

i need some bash code that can go to all domain and delete the folder after it will copy the new folder of my CMS.

1: delete:
run script for all the accounts /home/*/domains/*/public_html/admin/FOLDERTODELTET and delete the folder.

2: update:
run script for all accounts and copy the folder from some place in the server like
/tmp/SOMEFOLDER - to the same place that i delete.


again i'm sorry about my English i hope some understand and can help me ...
 
deleting is easy.

Code:
find /home/*/domains/*/public_html/admin/foldertodelete -exec rm -rf {} \;

Copying is a bit more involved because you have to perserve ownership of the files.

Code:
cp -rfp /tmp/folder /home/*/domains/*/public_html/admin/
cd /home
for i in `ls`; do { chown -R $i:$i $i; }; done;
 
Hello and THANK YOU!
I will try this but ....

When I delete the folder to any folder has a different name, but they all start at adm_
For example:

adm_1
adm_2
adm_3

I can do this ??

# find /home/*/domains/*/public_html/adm_*/FOLDERTODELTE -exec rm -rf {} \;
 
Yes i suppose that will work aswell.

Maybe you can build a temp structure for test purpose before do that in production ;)

Regards
 
I can do this ??

# find /home/*/domains/*/public_html/adm_*/FOLDERTODELTE -exec rm -rf {} \;


If you hesitate to run a command with deleting files, then try this simple way to list what is found:

Code:
find /home/*/domains/*/public_html/adm_*/FOLDERTODELTE | less

With that you won't get any files deleted, but listed.
 
Thank you all - SeLLeRoNe & zEitEr

I run this to output to file in root folder:

Code:
# find /home/*/domains/*/public_html/adm_*/FOLDERTODELETE > ~/update.log

and i see in the file all domain and is all good ! again thank you all !!!

now this is the safe way to do the copy think ?

# cp -rfp /tmp/SOMEFOLDER /home/*/domains/*/public_html/adm_*/
# cd /home
# for i in `ls`; do { chown -R $i:$i $i; }; done;

i ask again because I fear to do this on production server ...
 
Code:
now this is the safe way to do the copy think ?

# cp -rfp /tmp/SOMEFOLDER /home/*/domains/*/public_html/adm_*/
# cd /home
# for i in `ls`; do { chown -R $i:$i $i; }; done;
i ask again because I fear to do this on production server ...

This is really safe :cool:
 
Please help !!!

PLEASE HELP !!!

ok i delete the folder that i want and its all ok but

cp -rfp /tmp/FOLDERTOUPDATE /home/*/domains/*/public_html/adm_*/ <----- THIS NOT WORK !!!
it copy all files in all DA folder public_html to the last domain all bug !!


PLEASE HELP ME I'M STUCK !!!
 
I found this ....

Code:
#!/bin/bash
#Written by Rich Johnson, 2011
#free to modify, free to use

UHOME="/home"

# THIS IS THE FILE YOU WANT TO COPY TO EVERYONE
FILE="/home/rich.johnson/Desktop/twinkle.desktop"

# GENERATES ALL THE USER NAMES THAT ARE ON THE LDAP SERVER
USERSUSERS="$(ldapsmb -l -u | cut -d: -f1)"

# COPIES THE FILE TO EVERYONE
for u in $USERSUSERS
do

   # WHERE YOU WANT TO COPY TO
   _dir="${UHOME}/${u}/Desktop"
   if [ -d "$_dir" ]
   then
      cp -v "$FILE" "$_dir"

      # CHANGE THE OWNER OF THE FILE TO THE USER YOU COPIED TO
      chown $(id -un $u):users "$_dir/twinkle.desktop"
   fi
done

this help you guys ??
 
Please help me :(
Wildcards just don't work that way. The only way to do what you need to do is to write a loop. You can do something similar to Rich Johnson's example, but it will require extensive customizations. I and others can probably write it for you, but if I do it, it's going to take time and cost money (and if I write it it's going to be tested before I turn it over to you, so I may not be as inexpensive as some others would be).

Jeff
 
Back
Top