LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2009, 05:35 AM   #1
novice82
LQ Newbie
 
Registered: Oct 2009
Posts: 13

Rep: Reputation: 0
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
 
Old 10-05-2009, 06:14 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
Old 10-05-2009, 06:20 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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.
 
Old 10-05-2009, 07:50 AM   #4
novice82
LQ Newbie
 
Registered: Oct 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
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
 
Old 10-05-2009, 08:08 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

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


Reply

Tags
directory, files


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to batch process-modify ip numbers in files. SupermanInNY Programming 5 08-13-2009 04:03 AM
shell script - auto ftp files that older than 60 days bakeng Linux - Newbie 2 12-25-2007 11:35 PM
Generate a random number from a bourne shell script lothario Linux - Software 2 03-02-2007 12:01 AM
KDE Random wallpaper or script to create symbolic links to random files cvelasquez Linux - Software 2 02-26-2007 07:48 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration