... using Blosxom to retrace my steps

tstigers.net - Home :: Entries :: Feeds :: Photos
April 2024
Sun Mon Tue Wed Thu Fri Sat
 
       


Fri, 07 Dec 2007

Relative links in Blosxom (4): fixed

The version of the rename command on my remote server is from 2000 or so and doesn't understand perl expressions. Instead, it works like "from to file".
So I had to change the last line of my script to:

rename txt.new txt *.new

I then ran the script in each directory. Now everything seems OK. Good-bye, relative paths!

Posted on 07 Dec 2007 at 16:40 in /technology/internet/blosxom. -- Permalink

Copying while preserving file attributes

cp -p will do the trick - will preserve file attributes, including timestamps, when copying files. So much for low-level copying. I love man pages ... Obviously this is not a solution for FTP, but I can make a copy of my Blosxom blog on the remote server before I start changing files with my script.

Posted on 07 Dec 2007 at 14:34 in /technology. -- Permalink

Relative links in Blosxom (3)

The final version of my little shell script is here ... I had to keep the original files in order to set the timestamps of the corrected files back. This is why the original files couldn't simply be overwritten with the corrected ones. In the end, however, obviously the original files had to be discarded and the corrected files had to be given the same names as the original ones.

#/bin/bash
for i in *.txt;
do sed 's/href="blosxom\.cgi/href="http://\/\/tstigers\.net\/cgi-bin\/blosxom\.cgi/g' $i > $i.new;
touch -r $i $i.new;
done;
rm *.txt;
rename 's/\.new//' *.new

This works fine locally. If anything goes wrong when I run it on my remote server, I'll have wrecked my whole Blosxom blog. But what's the alternative? Blosxom's dependence on file timestamps makes it difficult to create backups. I guess I should have a look at low-level copying.

But maybe it's enough to write a script which copies all files and folders of the Blosxom blog and sets the timestamp of each copied file according to the timestamp of the original file. Such a script wouldn't change anything in the original place - no writing there, only reading.

So the problem of recursively entering directories comes up again. Well, I guess it's still easier to run such a script in every single directory and pass it the correct path to the original files every time.

Posted on 07 Dec 2007 at 14:08 in /technology/internet/blosxom. -- Permalink

Relative links in Blosxom (2)

I found writing a script which changes relative to absolute paths less trivial than I had anticipated.

Editing multiple files in vim ("argdo") is OK - but what happens when your command doesn't apply to all open files (e.g. because you want to substitute something which in some of these files just isn't there)? vim doesn't just skip them but refuses to do anything in any file.

Regarding sed, at first I didn't realise that by default all output is written to standard output, so you have to pipe the output into a file if you want your substitutions to be permanent. Now I've got a simple shell script which loops through all file names in a directory, substitutes relative links with absolute ones and writes the result in a new file:

#/bin/bash
for i in *.txt;
do sed 's/href="blosxom\.cgi/href="http://\/\/tstigers\.net\/cgi-bin\/blosxom\.cgi/g' $i > $i.new;
done

I'm sure that this is not the most elegant solution - but it works. It would be nicer to have a script which does the trick recursively for all directories; but with the handful of directories I have, entering every directory by hand and running the script there is probably easier than writing and testing such a fully automatic script.

Next step: reading the timestamp of each original file and setting the timestamp of each new file to the timestamp of the corresponding original file. It shouldn't be too difficult to do this by incorporating a "touch" command into my script. Finally, I'll need to run this script on my server: downloading all Blosxom text files to my local machine changes the timestamps, of course.

Posted on 07 Dec 2007 at 13:19 in /technology/internet/blosxom. -- Permalink


Powered by Blosxom RSS feed: /index.rss