Thank you very much for who can solve this bash script:
"Create a bash procedure createdata that creates collections (directories) that that will have to contain a random number, comprised between 300 and 600, of binary files of dimension comprised between 10 Kbytes and 30 kbytes.
Also the names of the files are random and are composed from 20 chars plus the jpg extension."
#!/bin/sh
mkdir $1
number=$2
while $number > 0; do
mkdir collectionnumber$number
numbermaxfile4folder=here I have to assign a RANDOM BETWEEN 300 AND 600 (how ???)
firstpartoffile=$(date)
chars=$RANDOM
echo chars > $firstpartoffile000000.jpg (to fill up a file of an amount of bytes..it should be between 10 and 30..)
done
number=$number-1
cp -r collection$number /data
can anyone help me to solve the full version? This is incomplete and I think also wrong..
Please help I'm totally newbie :(((
(to fill up a file of an amount of bytes..it should be between 10 and 30..)
chars=(
a b c d e f g h i j k l m n o p q r s t u v w x y z \
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
1 2 3 4 5 6 7 8 9 0
)
function random_string {
length=${1:-10}
for ((i = 0; i < length; i++)); do
echo -n ${chars[ (( ${RANDOM} % ${#chars[@]} )) ]}
done
echo
}
random_string 20
#!/bin/sh
mkdir data
cd $data
number=$2
while $number > 0; do
mkdir collection$number
cd $collection$number
numberoffilemax=$(($RANDOM % ( $600 - $300 + 1 ) + $300))
while $numberoffilemax > 0; do
firstpartoffile=$(date)
chars=random_string()
echo chars > $firstpartoffile000000.jpg
numberoffilemax=$numerofilemax-1
done
cd ..
number=$number-1
done
chars=(
a b c d e f g h i j k l m n o p q r s t u v w x y z \
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
1 2 3 4 5 6 7 8 9 0
)
function random_string {
length=${1:-10}
for ((i = 0; i < length; i++)); do
echo -n ${chars[ (( ${RANDOM} % ${#chars[@]} )) ]}
done
echo
}
chars=(
a b c d e f g h i j k l m n o p q r s t u v w x y z \
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
1 2 3 4 5 6 7 8 9 0
)
function random_string {
length=${1:-10}
for ((i = 0; i < length; i++)); do
echo -n ${chars[ (( ${RANDOM} % ${#chars[@]} )) ]}
done
echo
}
random_string 20
how to assign the value of the function in a shell script?