30.9.05

A One Liner to Change File Bits

Here's a little one-line command that will search all files in a directory with a given filename, and do a text substitution on them:

find . -name "*.html" -exec perl -pi -w -e 's/BADREGEX/GOODWORD\//g;' {} \;

In this case, I'm searching the current directory for all files with the '.html' extention. I'm then replacing all instances of 'BADREGEX' in the file with 'GOODWORD'.

If you pull the perl out of the command, you can use it on individual files:

perl -pi -w -e 's/BADREGEX/GOODWORD\//g;' [filename]

5.5.05

One in the rsync...

So, rsync is your friend. You should hug it, and love it, and buy it a sticky bun and hot chocolate every now and then when its feeling lonely. Here's what I know about it:

/usr/bin/rsync -azv                -e /bin/ssh \ 
               --rsync-path=/usr/bin/rsync \ 
               /web_directory new.webserver.net:/web_directory

OPTIONS:

 -a    Archive mode (enables recursion and preserve everything)

 -z    Compress file data (gzip)

 -v    Verbose (see all the deets)

 -e    Specify the rsh/ssh to use

 -n    Do a dry run (just show what would be done w/o actually 
     doing it)

 /bin/ssh   Path to the ssh, used with -e above

 --delete   Delete files on new.webserver.net that don't exist on 
     old.webserver.net

 --rsync-path=... Path to rsync on new.webserver.net

 /web_directory Path to rsync from

 new.webserver.net:/web_directory
     Host and path to rsync on new.webserver.net

Executing this command as demonstrated here will result in a large output dumped directly to the screen. You can save these to text by appending:

> /tmp/rsync-new.webserver.net:web_directory.log

or something of the ilk. Of course, you can name your log files whatever you want, but I prefer overly descriptive names myself.

Here's a couple more examples:

1) Sync /web_dir on test server from production server (on production server)

rsync -azv --delete -e /usr/bin/ssh --rsync-path=/usr/bin/rsync \
  /web_dir test.webserver.net:/web_dir > \ 
 /tmp/rsync-test.webserver.net:web_dir.log

2) Sync from /web_dir/web_app on build server to production server (on production server)

rsync -azv --delete -e /usr/bin/ssh --rsync-path=/usr/bin/rsync \
 build.webserver.net:/dev_dir/web_app /web_dir/web_app > \
 /tmp/rsync-build.webserver.net:web_dir:web_app.log

3) Pretend to sync from /web_dir/web_app on build server to productions server (on build server)

rsync -azvn --delete -e /usr/bin/ssh --rsync-path=/usr/bin/rsync \
 /dev_dir/web_app production.webserver.net:/web_dir/web_app > \
 /tmp/rsync-production.webserver.net:dev_dir:web_app.log

23.2.05

Some vegetarian recipes

I've been a member of a Vegetarian group on the campus portal (P.A.W.S.), even though I'm not a vegetarian. I haven't been checking it religiously, but I was having a look, and some of the members had posted some lovely looking recipes. I thought this would be a good place to post them for my future reference, and for anyone else that happens (hah!) to be reading my blog.

So, without further ado, I present Vegetarian Chili, and Pad Thai.

Murray Richelhoff's Vegetarian Chili:

1 tbsp Olive Oil
1 medium Onion
3 cloves of Garlic
1 pkg Extra Firm Tofu
1 can of Minced Tomatoes
1 can of Tomato Paste
1 tsp Curry
1/2 tsp Cumin
3 tbsp Chili Powder
Optional: Black Beans, Kidney Beans, Mushrooms, Plum Tomatoes, Chic Peas, Corn, etc, to taste.

Saute the onion and garlic in olive oil for 5 minutes. Add the tofu, and sautee for 15 minutes.

Add the curry, cumin, chili powder, tomatoes, tomato paste, and desired veggies. Simmer for 10 minutes.

Candace Beisel's Pad Thai

8 ounces Uncooked Rice Noodles
1/4 cup Vinegar
3 tbsp Tomato Paste
3 tbsp Water
2 tbsp Sugar
2 tbsp Olive Oil
2 cloves Garlic, Minced
1 Green Chili Pepper, Seeded and Minced
2 Eggs
1 c Bean Sprouts
1/3 c Chopped Unsalted Peanuts
garnish: Lime Wedges and Scallions/Green Onions, Chopped.

Soak noodles in boiling water, according to package directions. Drain and set aside.

In a bowl blend vinegar, tomato paste, sugar, water.

In a frying pan heat oil and stir fry garlic and chili pepper on medium heat 3 minutes.

Add tomato mixture. Make a well in the centre, crack eggs into it, cook til eggs almost set, about 2 nimutes, then stir quickly into the sauce.

Continue to simmer on low 4 to 5 minutes or until sauce is very thick.

Stir in noodles and remove from heat.

To serve, put the noodles and sauce on one side of the plate, and sprouts and peanuts on the other side. Garnish with the lime and scallions/green onions.