Category Archives: Handy BASH Scripts

Create a file with email addresses / usernames

Quickly create a list of email addresses / usernames in the format usernameprefixNumber@domain.name

 

#!/bin/bash
userprefix=$1;
numberofusers=$2;
domain=$3;
filetosave=$4
counter=1;

if [ $# -ne 4 ]; then
echo Insufficient arguments:
echo "Usage: $0 userprefix numberofusers domainname filetosave"
echo " - enter user prefix, e.g. demo"
echo " - enter number of users,e.g. 100"
echo " - enter domain/hostname, e.g. some-hostname.domain.com"
echo " - file to save the result in"
exit 1
fi

touch $4 ;


while [[ $counter -le $numberofusers ]];
do echo Creating User $counter;
echo "$userprefix$counter@$domain" >> $4;
let "counter += 1";
done
Advertisements

Create files with certain size

What it does:  The script will create certain number of files with certain size. It takes two arguments – first is the number of files and the second is the size of each file ( in kilobytes ).

Usage:  ./script.sh 100 1
(this will create 100 files 1MB each)

Code:

#!/bin/bash
filecount=$1;
blocksize=$2;
counter=1;
while [[ $counter -le $filecount ]];
do echo Copying $counter;
dd if=/dev/zero of=filename$counter bs=$2k count=1024
let "counter +=1";
done