Linux copy and overwrite bash script

Discussion in 'Domains, Hosting and Servers' started by Dan Hutter, Oct 13, 2012.

  1. Dan Hutter

    Dan Hutter aka Big Dan

    Joined:
    Jul 20, 2006
    Messages:
    1,412
    Likes Received:
    515
    Location:
    New York
    Hi Guys,

    I'm looking to write a simple bash script to upgrade plugins on many Wordpress sites at once. Personally, I recommend running as little plugins as possible but my client insists on duplicating is plugins across every WP install he has which is many. Please don't lecture me about the performance hit of a lot of plugins -- I've gone over it with him many times and it's fallen on deaf ears.

    My idea is to keep a 'master install' for each user account on the server which will manually updated through the Dashboard. Then create a simple little script to just copy the files to all the other domains thus updating the plugins in one shot.

    Here's my rough idea of the script. I'm not sure if cp supports -rf. That means I want it to recurse into subdirectories and force (overwrite) files that already exist.

    Code:
    cp -rf /home/user/mastersite.com/wp-content/plugins/* /home/user/slavesite.com/wp-content/plugins/
    cp -rf /home/user/mastersite.com/wp-content/plugins/* /home/user/slavesite2.com/wp-content/plugins/
    cp -rf /home/user/mastersite.com/wp-content/plugins/* /home/user/slavesite3.com/wp-content/plugins/
    cp -rf /home/user/mastersite.com/wp-content/plugins/* /home/user/slavesit3.com/wp-content/plugins/
    
    Or am I better off just tarballing the master sites's plugins directory and untaring it to the slave site?

    Thanks in advance for your help.

    -Dan
     
  2. digitalpoint

    digitalpoint Regular Member

    Joined:
    Jul 9, 2012
    Messages:
    193
    Likes Received:
    313
    Location:
    San Diego, California
    Yes... cp supports recursive... you don't need the -f flag... that's more if there's something weird going on (inability to read the destination file).

    If all wordpress plug-in directories end up being the same, you could use a symbolic link for that directory if all the sites are on the same directory... then you would have 1 directory that is available at multiple locations on the server.
     
    Dan Hutter likes this.
  3. Dan Hutter

    Dan Hutter aka Big Dan

    Joined:
    Jul 20, 2006
    Messages:
    1,412
    Likes Received:
    515
    Location:
    New York
    symlink is a great idea Shawn! Thank you. :)
     

Share This Page