Generate IP-address ranges using simple bash script

This is just a simple script to generate IP-addresses in a IP-range and write the result output to a file.
The script does also remove addresses you would like to exclude from the final output.

#!/bin/bash
OUTFILE="mk-iprange.txt"
IPRANGE="192.168.0 
192.168.1"
EXCLUDE="192.168.0.1
192.168.0.2
192.168.1.1"

# Remove old OUTFILE
rm -f $OUTFILE

# Loop addresses, write to OUTFILE
for IP in $IPRANGE
do
        seq -f "$IP.%g" 1 255 >> ./$OUTFILE
done

# Exclude IP-addresses from file (inplace replacement)
for EX in $EXCLUDE
do
        sed --in-place "/$EX/d" ./$OUTFILE
done

Backup VMware ESXi using BazaarVCB

This post describes how you can backup your VMware ESXi home installation with free license using BazaarVCB if you do not have a vCenter Server available. Bazaarvcb is the fastest backup solution I have used on the free VMware hypervisor.
Download the latest version from the download page.

The backup script is run by crontab every night and looks like this

#!/bin/bash
bazaarvcbPath="/media/backup/bazaarvcb-0.9.7b-linux-i386/bazaarvcb"
backupsPath="/media/backup"
hostname="192.168.0.222"
username="root"
password="password"
rollOut="30"
vmNames="vm-guest1 vm-guest2 vm-guest3"

for VM in $vmNames; do
        `$bazaarvcbPath backup -H $hostname -u $username -p $password --roll-out $rollOut $VM $backupsPath/$VM`
done

The backups are full so make sure you have enough disk space available.

bazaarvcb options

$ bazaarvcb -h
usage: bazaarvcb [-h]  ...

optional arguments:
  -h, --help   show this help message and exit

valid commands:
    checkhash  check .hsh files integrity in one directory
    listvm     list registered VMs on the ESXi host
    queryvm    display VMs informations
    listbackup
               search for backups in local and remote directories
    querybackup
               display report file of one particular
    backup     backup a VM
    restore    restore a backup

Open TCP port 31031 in your firewall to ensure that you have a high transfer rate, otherwise the backup will be transferred over SSH protocol and will be capped in speed to about 7MB/s (on the free hypervisor).
Bazaarvcb cannot backup a VM with snapshot(s).

Warning!
I have not tested this on a host connected to a vCenter server and can not confirm that it will work or not.

Another way to randomize filenames

This post describes an easier way to randomize filenames using the command openssl compared to my previous post named Randomize filenames.

#!/bin/bash
for filename in *.JPG
do
mv "$filename" $(echo "$filename" | openssl rand -hex 3).JPG
done

After running this script the filenames can look something like this

26333c.JPG
a8c7a0.JPG
b16b22.JPG
d69a67.JPG
...

The rand option creates a random value from $filename.

Create random filenames with random content

I wanted to test filesystem checking on a large XFS filesystem and needed to fill the filesystem. The task was to create files on random with different file size and names placed in different folders.

The script I found on the Internet does exactly that

#!/bin/bash
# Created by Ben Okopnik on Wed Jul 16 18:04:33 EDT 2008
######## User settings ############
MAXDIRS=15
MAXDEPTH=7
MAXFILES=100000
MAXSIZE=8000000000
######## End of user settings ############
# How deep in the file system are we now?
TOP=`pwd|tr -cd '/'|wc -c`
populate() {
cd $1
curdir=$PWD
files=$(($RANDOM*$MAXFILES/32767))
for n in `seq $files`
do
f=`mktemp XXXXXX`
size=$(($RANDOM*$MAXSIZE/32767))
head -c $size /dev/urandom > $f
done
depth=`pwd|tr -cd '/'|wc -c`
if [ $(($depth-$TOP)) -ge $MAXDEPTH ]
then
return
fi
unset dirlist
dirs=$(($RANDOM*$MAXDIRS/32767))
for n in `seq $dirs`
do
d=`mktemp -d XXXXXX`
dirlist="$dirlist${dirlist:+ }$PWD/$d"
done
for dir in $dirlist
do
populate "$dir"
done
}
populate $PWD

Source: http://linuxgazette.net/153/pfeiffer.html