| | |
HELP! Who can solve this bash script?
![]() |
•
•
Join Date: Jun 2007
Posts: 7
Reputation:
Solved Threads: 0
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."
Working sample:
it must create therefore beyond to the directory given (data) the subdirectory tlc01, then the 20 collections (subdirectories of tlc01)
Sorry for my english, hope you understand..
Thanks indeed for who can help me :-)
"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."
Working sample:
Shell Scripting Syntax (Toggle Plain Text)
createdata /data 20 result: /data tlc01 collection001 ttretdgdfgasjojgvao.jpg grtghgfhysystudbbnh.jpg ... ... collection019 ...
Sorry for my english, hope you understand..
Thanks indeed for who can help me :-)
•
•
Join Date: Jun 2007
Posts: 7
Reputation:
Solved Threads: 0
yes I tried this:
can anyone help me to solve the full version? This is incomplete and I think also wrong..
Please help I'm totally newbie
((
Shell Scripting Syntax (Toggle Plain Text)
#!/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
Please help I'm totally newbie
(( Last edited by alexxxprog; Jun 1st, 2007 at 5:32 pm.
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 39
•
•
•
•
...
numbermaxfile4folder=here I have to assign a RANDOM BETWEEN 300 AND 600 (how ???)
...
Shell Scripting Syntax (Toggle Plain Text)
# start=300 # end=600 # echo $(($RANDOM % ( $end - $start + 1 ) + $start)) 401
•
•
•
•
(to fill up a file of an amount of bytes..it should be between 10 and 30..)
Shell Scripting Syntax (Toggle Plain Text)
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
•
•
Join Date: Jun 2007
Posts: 7
Reputation:
Solved Threads: 0
thank you very much ghostdog74!
My code then is this:
Thank you again!
My code then is this:
Shell Scripting Syntax (Toggle Plain Text)
#!/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 }
Thank you again!
Last edited by alexxxprog; Jun 2nd, 2007 at 6:42 am.
•
•
Join Date: Jun 2007
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
Shell Scripting Syntax (Toggle Plain Text)
# start=300 # end=600 # echo $(($RANDOM % ( $end - $start + 1 ) + $start)) 401
#!/bin/bash
start=300
end=600
echo $(($RANDOM % ( $end - $start + 1 ) + $start))
tryrandom.bash: line 2: 19345 % -1 + : syntax error: operand expected (error token is " ")
why?
•
•
Join Date: Jun 2007
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
[code]
Shell Scripting Syntax (Toggle Plain Text)
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
thanks!
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 39
•
•
•
•
how to assign the value of the function in a shell script?
thanks!
Shell Scripting Syntax (Toggle Plain Text)
# function test() { return 1; } # var=$(test) # echo $? 1
![]() |
Similar Threads
- how to recursive search of subdiretories in BASH script (Shell Scripting)
- Bash Mail script help (Shell Scripting)
- web page statistics - my first bash script (Shell Scripting)
- Bash script prob (Kernels and Modules)
Other Threads in the Shell Scripting Forum
- Previous Thread: What does @ mean???
- Next Thread: Fedora Resolution
| Thread Tools | Search this Thread |






