The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How To replace Control-M in all files in a folder padpa Shell Programming and Scripting 10 09-02-2008 07:58 AM
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 03:44 PM
Parse the .txt file for folder name and FTP to the corrsponding folder. MeganP Shell Programming and Scripting 3 07-03-2007 02:54 PM
Take a folder name and find it in another folder (Complicated) hkhan12 Shell Programming and Scripting 5 09-06-2006 01:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-19-2008
jimmack jimmack is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 1
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 (permalink)  
Old 04-20-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0