LinuxQuestions.org
Have you heard the LinuxQuestions.org Podcast?
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools
Old 10-05-2009, 05:35 AM   #1
novice82
LQ Newbie
 
Registered: Oct 2009
Posts: 13
Thanked: 0
shell script to auto process ten random files and generate logs


[Log in to get rid of this advertisement]
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
windows_xp_2003 novice82 is offline     Reply With Quote
Old 10-05-2009, 06:14 AM   #2
zhjim
Member
 
Registered: Oct 2004
Distribution: Debian lenny & etch, Red Hat 4.0, (used slackware 11.0)
Posts: 439
Blog Entries: 2
Thanked: 29
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
windows_xp_2003 zhjim is offline     Reply With Quote
Thanked by:
Old 10-05-2009, 06:20 AM   #3
catkin
Senior Member
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Slackware 13.0
Posts: 1,840
Blog Entries: 6
Thanked: 226
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.
linux catkin is online now     Reply With Quote
Thanked by:
Old 10-05-2009, 07:50 AM   #4
novice82
LQ Newbie
 
Registered: Oct 2009
Posts: 13
Thanked: 0

Original Poster
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
windows_xp_2003 novice82 is offline  
Tag This Post , , , ,
Reply With Quote
Old 10-05-2009, 08:08 AM   #5
konsolebox
Member
 
Registered: Oct 2005
Location: Philippines
Distribution: Gentoo, Slackware
Posts: 957
Thanked: 15
concept:
Code:
FILES=(<put 10 files here>)
TARGETFILE="${FILES[$(( RANDOM % 10 ))]}"
: do something with "$TARGETFILE"
windows_xp_2003 konsolebox is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


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

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration