我在生产服务器上维护了大量的wordpress安装,我们正在考虑部署InfiniteWP来pipe理这些安装。 我正在寻找一种方法来编写插件文件夹的分发到所有这些安装。
在服务器的wp-prod上,所有的站点都存储在/ srv / sitename / site /插件需要从〜/ iws-plugin复制到/ srv / sitename / site / wp-content / plugins /
这里有一些伪代码来解释我需要做什么:
array dirs = <all folders in /srv> for each d in dirs if exits "/srv/d/site/wp-content/plugins" rsync -avzh --log-file=~/d.log ~/plugin_base_folder /srv/d/site/wp-content/plugins/ else touch d.log echo 'plugin folder for "d" not found' >> ~/d.log end end
我只是不知道如何使它从cli或通过bash发生。 我可以(也将会)在我的testing服务器上修改bash或ruby脚本,但是我认为SF的命令行function足够强大,可以比我能够解决的问题更快地处理这个问题。
谢谢!
确定这里有一些bash ..首先,要获得所有插件目录的站点列表,你可以使用globbing和ls -d(即不要下载目录,只给目录条目)
例如:
for i in `ls -d /srv/*/site/wp-content/plugins` do #whatever rsync command you want to do, $i will evaluate to the directory name eg rsync -avzh /source/plugindir $i done
#second pass查找plugins目录不存在的所有情况。
LOGFILE = "/some/log" echo for i in ` ls -d /srv/*/site/wpcontent` do if [ ! -d ${i}"/plugins" ] then echo ${i}"is evil" > $LOGFILE fi done
我忽略了有关每个目录有专门的rsync日志文件的部分..我不知道你的意思是什么path〜/ d.log。 如果你真的想为rsync提供单独的日志文件,或者你可以使用awk,只分离出站点名称,并用它作为日志文件的基本名称,那么你可以用sed做一些事情来将斜杠改成破折号。 例如:
LOG=`echo $i | awk -F/ '{print $2}'`
我已经写了几个小时后,发布的阙,但没有代表和我自己的问题没有等待,所以我现在张贴。 我觉得cli命令或bash脚本可以更简洁地做到这一点,但是这是我写这个工作的原因,而且很清楚(甚至在我logging如此之前)
任何关于这个或其他解决scheme的反馈将不胜感激:
#!/usr/bin/env ruby # rrdist.rb # Utility script to copy the contents of a folder to multiple destinations # ****LOCAL USE ONLY (FOR NOW)****** # TODO: Make it interactive (get source and destination via std in or file) # Make it work remotely (rsync over ssh) require 'pathname' #set the log folder location log_folder = Pathname(File.expand_path('~')).join('logs') #TODO: get this at runtime and validate it #set the source folder source_folder = Pathname(File.expand_path('~')).join('iwp-client') #TODO: get this at runtime and validate it #set the destination parent folder dest_parent_folder = '/srv' #TODO: get this at runtime and validate it #get all the subfolders of the parent target_dirs = Dir.glob('/srv/*') #process each child folder target_dirs.each do |folder| #first, build the destination string for the rsync command destination = "#{folder}/site/wp-content/plugins/" #set up the name of the log file vhost = (Pathname(folder).each_filename.to_a)[1] #TO-DO: If the destination is gotten at run time, then this will not work - FIX IT! #set up the actual log log = "#{log_folder}/#{vhost}.rrdist.log" #make sure the destination exists! if File.directory?(destination) #build the rsync command command = "rsync -avzh --log-file=#{log} #{source_folder} #{destination}" puts "Executing #{command}" #check if the command exit code was 0 exit_code = system("#{command}") if !exit_code File.open("#{log}", 'a+') do |f| f.write("#{Time.now} -- [ERROR] -- #{folder} -- rsync command failed: #{command} \n") end end #when the destination isn't there, log it else puts "#{destination} doesn't exist!" #puts "Logfile written to #{log_folder}/#{vhost}.log" #write the log file (append or create if not there) File.open("#{log}", 'a+') do |f| f.write("#{Time.now} -- [ERROR] -- #{folder} -- Missing Plugin folder \n") end end end