Replace folder in all hosting accounts


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace folder in all hosting accounts
# 1  
Old 04-19-2008
Replace folder in all hosting accounts

I am trying to find out how to replace a folder that is located in every hosting account on the server I think this is possoble with a bash command of some sort?

The contents of this folder get updated from time to time and its getting to be a real pain doing it manually is there a way to do this via shell or some other method the folder in question is located inside the public_html folder of every account in the server.

Jim
# 2  
Old 04-20-2008
Sounds like you should find a different solution, longer term. What if users have customized some parts of the folder's contents?

Do you intend to keep a backup, or just replace whatever is there? What about permissions?

There is no single bash command which will do this, but a simple script would likely suffice.

Assuming all accounts exist under /home, something like

Code:
for f in /home/*/public_html/foldername; do
  cp --backup /path/to/master/* ${f}/
  home=${f%/public_html/foldername}
  user=${home#/home/}
  chmod $user $f/*
done

Assuming you have the master copy in /path/to/master, this will copy all files from that folder to each user's public_html/foldername, creating backup files if any files would be overwritten. (Your local implementation of cp might not have the --backup option -- you want to look into that first.)

Then it uses a couple of simple substitutions to extract the user name from the path, and changes the ownership of all files in the destination folder so they belong to the user.

This is pretty brute force; perhaps you want to loop over each individual file and decide whether or not you even need to replace what's possibly already there. Then you could also preserve the user's customization if the user has removed one of these files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace the first and last character which is pipe symbol in all files within a folder?

with in my files i have the data like this, starting with a pipe and ending the line with a pipe. all i want is to replace the first and last pipe , remove those trying to use following sed command, but it is only showing on the screen the entire data of the file as if it removed, but when i... (4 Replies)
Discussion started by: cplusplus1
4 Replies

2. UNIX for Dummies Questions & Answers

MilesWeb.com shared hosting or unlimited hosting plans?

I want to host a website in India, after all my research I have found MilesWeb.com, I am planning to go for their shared plan http://www.milesweb.com/cpanel-hosting.php I have test their contact options and response time, they are really available 24/7. I have checked few other providers, they... (1 Reply)
Discussion started by: Guruguy
1 Replies

3. Shell Programming and Scripting

Replace part of folder(s)

I have a script that will output folders that all end with "x.deb". I want a shell script snippet that removes the "x.deb" from all those folders. Thanks in advance. (27 Replies)
Discussion started by: pasc
27 Replies

4. Shell Programming and Scripting

Find and replace folder of files with $var

I want to scan through all the files in the folder and replace all instances of $file_X within the file with the variable $X defined in my bash script on my debian 6.0 install. For example, if the file contains $file_dep I want it to be replaced with the value of the variable $dep defined in my... (1 Reply)
Discussion started by: Spadez
1 Replies

5. Shell Programming and Scripting

To replace a string in file by its parent folder name.

Hi all, I have a directory structure like "folder1/folder2/website_name/folder3/folder4/file.php." I need to write a script which will enter into file.php and replace a particular string of characters with "website_name" folder name. In folder2,there are many such website's folders kept.So... (4 Replies)
Discussion started by: arien15488
4 Replies

6. Shell Programming and Scripting

Replace last 2 folder directory string with sed

Hi guys, I´m trying to replace the 2 last folders name in a list of directories with a new string, but I´m don´t know which regex to apply. Directories list: C/my user/documents/games & music C/my user/documents/photos 09-24-2008 C/my user/settings/config ?1_2 * The last folder may have... (11 Replies)
Discussion started by: cgkmal
11 Replies

7. UNIX for Advanced & Expert Users

Shared hosting, how to install programs and libraries in your home folder

Hi all I hope I am posting in the right section. If not please excuse me and redirect me to the right section. Here is my problem: I am using a shared hosting plan at Godady. I have shell access and of course my own folder. I would like to be able to install programs in my own folder... (4 Replies)
Discussion started by: PiniFarini
4 Replies

8. Shell Programming and Scripting

How To replace Control-M in all files in a folder

hi all, I copied set of files from a linux machine to an aix machine but in binary mode copy , ASCII mode copy both leed to control M charecters in most of the files. Any shell script/C script to remove control M charecters in all files in a given directory. Pls reply if you are aware... (10 Replies)
Discussion started by: padpa
10 Replies

9. Shell Programming and Scripting

Replace string in all files in a folder and subfolders.

i need to change string in all files in current folder and all subfolders. i wrote the following script. It works good except it dont delete temp file from subfolders. for z in `find . -type f -name "*.html" -o -name "*.htm"`; do sed -e 's@abc@xyz@g' $z>temp; mv temp $z; done any idea?... (1 Reply)
Discussion started by: crazynups
1 Replies
Login or Register to Ask a Question