LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script to auto process ten random files and generate logs (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-to-auto-process-ten-random-files-and-generate-logs-759773/)

novice82 10-05-2009 04:35 AM

shell script to auto process ten random files and generate logs
 
Hello member's

I'm learning to script in the ksh environment on a Solaris Box.

I have 10 files in a directory that I need to pass, as input to a batchjob one by one. lets say, the files are named as follows;
abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).

How do I go about achieving the following :

I want my batch script to take one file at a time from the current directory and process it, redirect the console output to a logfile (log1.txt, log2.txt etc )

./batch_script.ksh > log1.txt -- likewise, create 10 log files and exit

for simplicity sake, contents of the script:

Code:

#! /bin/ksh

mv abcd.txt ./temp/
echo "test script"

### End of SCript ####

regards,

Kris

zhjim 10-05-2009 05:14 AM

I'd use a wrapper and do something like this

for i in $(ls); do
./$i
done

That should run every file in the current directory

catkin 10-05-2009 05:20 AM

Or maybe
Code:

for i in $(ls); do
      batchjob $i > log$i.txt 2>&1
done

It will not work if you have any spaces in the file names though.

novice82 10-05-2009 06:50 AM

Quote:

Originally Posted by catkin (Post 3708166)
Or maybe
Code:

for i in $(ls); do
      batchjob $i > log$i.txt 2>&1
done

It will not work if you have any spaces in the file names though.

Thanks Catkin.

That was exactly what I was looking for.

Kris

konsolebox 10-05-2009 07:08 AM

concept:
Code:

FILES=(<put 10 files here>)
TARGETFILE="${FILES[$(( RANDOM % 10 ))]}"
: do something with "$TARGETFILE"



All times are GMT -5. The time now is 07:21 PM.