Convert a bunch of wav files into mp3 format

Use the following statement to convert a bunch of waveform audio format (wav) files within a folder into mp3 format. The script is based on the well known lame mp3 encoder.

bash# for line in $(ls  .wav | perl -pe 's/(.).wav/$1/'); \
do lame -b 192 -h $line.wav $line.mp3 ; done;

Resize multiple images using Imagemagick

Ever tried to resize a whole folder of images in a single line? Make sure you have  the imagemagick convert utility installed. Paste to following line into your bash

bash# ls -1 *.jpg > images; while read line; do SRC=$line; cp $line temp.jpg; convert -resize 400x400 temp.jpg $SRC; done < images; rm images temp.jpg

The command will resize alle images to 400 pixels height or width depending on the orientation of the image. Thus, the propotions of the image will not change.

Extract Content of Multi-part Uuencoded Binaries

I’ve been looking for a simple way to extract parts of a uuencoded file and stumbled over an old sed paper covering sed one-liners.

However, Use sed to extract multi-part uuencoded binaries and to remove extraneous header info, so that only the uuencoded portion remains. Files passed to sed must be passed in the proper order.
sed '/^end/,/^begin/d' file1 file2 ... fileX | uudecode

Clone an OpenVZ VE

Upgrade system to clone
hn# vzctl start veid-to-clone
hn# vzctl enter veid-to-clone
ve# yum update
ve# exit
hn# vzctl stop veid-to-clone

Run clone script with required attributes
hn# ./clone.sh
Usage ./clone.sh old_id new_id new_ip

hn# ./clone.sh 1 123 192.168.1.123
Stopping ve1...
Unable to stop: container is not running
Copying configuration...
Cloneing ve1...
Updateing ve123 configuration...
Starting clone...
Starting container ...
Initializing quota ...
Container is mounted
Adding IP address(es): 192.168.1.123
Setting CPU units: 1000
Configure meminfo: 65536
Set hostname: ve123.example.com
File resolv.conf was modified
Container start in progress...
Starting origin ve...
Starting container ...
Container is mounted
Adding IP address(es): 192.168.1.1
Setting CPU units: 1000
Configure meminfo: 65536
Set hostname: ve1.example.com
File resolv.conf was modified
Container start in progress...
Done.

Be aware that the script automatically stops and starts the origin VE as well as the cloned VE. Clone bash script below

#! /bin/bash

if [ $# != 3 ]; then
echo "Usage $0 old_id new_id new_ip"
exit 0
fi

OLDVE=$1
NEWVE=$2
IP=$3

echo "Stopping ve$OLDVE..."
vzctl stop $OLDVE
echo "Copying configuration..."
mkdir /vz/root/$NEWVE
cp /etc/vz/conf/$OLDVE.conf /etc/vz/conf/$NEWVE.conf
mkdir /vz/private/$NEWVE
echo "Cloneing ve$OLDVE..."
pushd /vz/private/$OLDVE; tar c --numeric-owner * | tar x --numeric-owner -C /vz/private/$NEWVE; popd
echo "Updateing ve$NEWVE configuration..."
cat /etc/vz/conf/$OLDVE.conf | grep -v "IP_ADDRESS" | grep -v "HOSTNAME" > /etc/vz/conf/clone.conf
echo "IP_ADDRESS="$IP"" >> /etc/vz/conf/clone.conf
echo "HOSTNAME="ve$NEWVE.haite.ch"" >> /etc/vz/conf/clone.conf
mv /etc/vz/conf/clone.conf /etc/vz/conf/$NEWVE.conf
echo "Starting clone..."
vzctl start $NEWVE
echo "Starting origin ve..."
vzctl start $OLDVE
echo "Done."