开发者

Copy/publish images linked from the html files to another server and update the HTML files referencing them

I am publishing content from a Drupal CMS to static HTML pages on another domain, hosted on a second server. Building the HTML files was simple (using PHP/MySQL to write the files).

I have a list of images refer开发者_JAVA技巧enced in my HTML, all of which exist below the /userfiles/ directory.

cat *.html | grep -oE [^\'\"]+userfiles[\/.*]*/[^\'\"] | sort | uniq

Which produces a list of files

http://my.server.com/userfiles/Another%20User1.jpg
http://my.server.com/userfiles/image/image%201.jpg
...

My next step is to copy these images across to the second server and translate the tags in the html files.


I understand that sed is probably the tool I would need. E.g.:

sed 's/[^"]\+userfiles[\/image]\?\/\([^"]\+\)/\/images\/\1/g'

Should change http://my.server.com/userfiles/Another%20User1.jpg to /images/Another%20User1.jpg, but I cannot work out exactly how I would use the script. I.e. can I use it to update the files in place or do I need to juggle temporary files, etc. Then how can I ensure that the files are moved to the correct location on the second server


It's possible to use sed to change the file in-place using the -i option.

For your use it's up to you if it's easier/better to create a new file with the changes from the old, then copy to the 2nd domain using scp (or something similar). Or it may be easier to copy the file first, then modify it once it's on the remote server (less management of new filenames this way).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜