howdi folks ,
i wrote a script that i am using to copy file to multiple files and generate random names to the copies. this part is working ,however when i am trying to run more sets of commands on the copies created it does not take all the copies but only one copy and run the commands on this one.
this is the script :
#!/bin/bash
## Script for copying a file to multiple files (mass copy) and generating random name to each file
##
## Main script
# VARS
COUNTER=0
echo "File to copy ? (full name)"
read filename
echo "Please select extension to new files (doc/pdf/exe/etc...)"
read ext
echo "How many copies to make ? (number)"
read numcopies
while [ $COUNTER -lt $numcopies ]; do
for i in $( cat /dev/urandom | tr -cd 'a-f0-9' | head -c 64 ); do
cp $filename $i.$ext
ls $i.$ext > /tmp/newfiles.txt
done
let COUNTER=COUNTER+1
done
#
## Diff test for files generated on this script only
# VARS
DIFF=$(diff $filename $i.$ext)
if [ "$DIFF" = "" ]
then
echo "Diff all files succesfully"
fi
#
## md5sum test for files generated on this script only
# VARS
TMP=/tmp/md5sum_test.txt
MD5=$(md5sum $filename $i.$ext > $TMP)
grep $filename $TMP | awk '{print $1}' | while read line;
do
GREP=$(grep -v $line $TMP)
if [ "$GREP" == "" ]
then
echo "md5sum's are matching"
else
echo "operation failed"
fi
done
exit 0
this is the out put i am getting :
root@myserver:/my/directory # ./copier.sh
File to copy ? (full name)
oren.doc
Please select extension to new files (doc/pdf/exe/etc...)
doc
How many copies to make ? (number)
20
Diff all files succesfully
md5sum's are matching
root@myserver:/my/directory # cat /tmp/newfiles.txt
bbfb46e1a0fabeab9343839dd2b8e13a254847f0890f809959decc669abd06fd.doc
root@myserver:/my/directory # cat /tmp/md5sum_test.txt
cc8bba3d80207cd0b9832eddf7781743 oren.doc
cc8bba3d80207cd0b9832eddf7781743 bbfb46e1a0fabeab9343839dd2b8e13a254847f0890f809959decc669abd06fd.doc
thanks in advance for any feedbacks...