Simple Batch File Help Needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Batch File Help Needed
# 1  
Old 01-11-2009
Question Simple Shell Script Help Needed!?!

I have access to a large unix parallel computing cluster. To submit jobs I simply run a script called "submit" followed by options relevant to that particular job. Very simple and easy, "submit" can be run from any directory.

I am trying to make a batch file that automatically runs "submit" in multiple directories. I essentially would like to elminate manually submiting jobs manually, because I may have 100's of jobs to submit.

The stucture is simple: /case*/job

Manually I would type the commands:

cd Case1
submit options
cd ..
cd Case2
submit options
cd ..
etc.

HOpefully this makes sense. It seems like it should be an easy problem to solve, but nothing I have done seems to work.

Last edited by cpabrego; 01-11-2009 at 07:36 PM..
# 2  
Old 01-11-2009
A simple batch file? Those run under MS-DOS and Windows.

Is the computer you are running on Linux or another UNIX-like system? If so then you probably want a shell script. It's more than just picky terminology--words mean things.

Anyway, how about this?
Code:
#!/bin/sh
cd /home/cpabrego/Case1
submit options
cd /home/cpabrego/Case2
submit options
cd /home/cpabrego/Case3
submit options

The first line, #!/bin/sh (or #!/bin/bash) declares this to be a shell script and tells what command processor to use. The other lines are just the commands you want to execute. I assume you have some submit command installed.
# 3  
Old 01-11-2009
Quote:
Originally Posted by KenJackson
A simple batch file? Those run under MS-DOS and Windows.

Is the computer you are running on Linux or another UNIX-like system? If so then you probably want a shell script. It's more than just picky terminology--words mean things.

Anyway, how about this?
Code:
#!/bin/sh
cd /home/cpabrego/Case1
submit options
cd /home/cpabrego/Case2
submit options
cd /home/cpabrego/Case3
submit options

The first line, #!/bin/sh (or #!/bin/bash) declares this to be a shell script and tells what command processor to use. The other lines are just the commands you want to execute. I assume you have some submit command installed.
Thanks for the reply!

Yes I meant to say shell script. The system is a UNIX system, Submit is also a shell script as you mention that I am using to submit jobs. I think the code you proposed will work I can test it.

However, because the number of case directories will vary, I would like to make the script more flexible. The number of cases varies from as few 5 to 100's and varies.

Is this possible?
# 4  
Old 01-11-2009
That depends on the real directory names and options. If they really are generic like that, then this might work.
Code:
#!/bin/sh
LIMIT=100
n=0
while test $n -lt $LIMIT; do
    cd /home/cpabrego/Case$n
    submit options
    ((n++))
done

or maybe this:
Code:
#!/bin/sh
DIRS="Case1 Case2 Case3 Case4 Case5"
DIRS="$DIRS Case6 Case7 Case8 Case9"

for d in $DIRS; do
    cd /home/cpabrego/$d
    submit options
done

# 5  
Old 01-11-2009
Quote:
Originally Posted by KenJackson
That depends on the real directory names and options. If they really are generic like that, then this might work.
Code:
#!/bin/sh
LIMIT=100
n=0
while test $n -lt $LIMIT; do
    cd /home/cpabrego/Case$n
    submit options
    ((n++))
done

or maybe this:
Code:
#!/bin/sh
DIRS="Case1 Case2 Case3 Case4 Case5"
DIRS="$DIRS Case6 Case7 Case8 Case9"
 
for d in $DIRS; do
    cd /home/cpabrego/$d
    submit options
done


Thanks for the info. The options for submit are strait forward and are in the form: submit -n 8 filename. Where file name will be constant in every case*.

One thing you pointed out will come into play. The directories will actually be called:
case001
case002
...etc
Which is a bit more complicated. Is this the same thing?

Code:
#!/bin/sh
DIRS="Case*"
DIRS="$DIRS"
 
for d in $DIRS; do
    cd /home/cpabrego/$d
    submit options
done

You have given me a great starting point, I will try your ideas and let the forum what works for me.
# 6  
Old 02-04-2009
Thanks for the replies, a late update I finally found time to run the scripts and for my needs this worked best.

Code:
 
#!/bin/sh
DIRS="case*"
DIRS="$DIRS"
for d in $DIRS; do
    cd $d
    submit options
    cd ..
done

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple awk script needed

but I'm stumped...please help I have a file like this....... 1000 1 34 1000 10 34 1000 11 35 1000 20 35 1000 21 36 1000 30 36 2000 1 34 2000 10 34 which I would like printed out as 40 lines 1000 1 34 1000 2 34 1000 3 34 1000 4 ... (2 Replies)
Discussion started by: garethsays
2 Replies

2. Shell Programming and Scripting

Simple if statement help needed please

if ]; then echo "successssssssssssssssssss" $filename = "<font color='red'>$i</font>" else echo "failureeeeeeeeeeeeeeeeeeeee" $filename = "$i" fi; I'm just trying to see is this - read a file name and highlight... (2 Replies)
Discussion started by: vmanda
2 Replies

3. Shell Programming and Scripting

Urgent simple script needed

Good Day All, I need your urgent support to get the following script (bash), (it should be as simple as possible please) : The script will check the .csv file( attached example) The script will generated 3 files from the initial one. The script must check one field “NEType”, and then ... (2 Replies)
Discussion started by: engkemo2002
2 Replies

4. Shell Programming and Scripting

parsing simple output help needed

Goal: for each hostname (mars, phobos, and deimos grab the value of state = in a variable so I work on it further. I figured I'll need to use sed to find the target host name, then substitute the "linefeed and what I am assuming is a tab state =" to null and grab the state (in this case "free")... (3 Replies)
Discussion started by: graysky
3 Replies

5. UNIX for Dummies Questions & Answers

Help needed to run simple java program in linux

Hi guys , This is the first time i m running java application inside linux. i have installed jdk-6u20-linux-i586-rpm.bin jre-6u20-linux-i586-rpm.bin in my linux machine. and set JAVA_HOME and JRE_HOME variables respectively. # echo $JAVA_HOME /usr/java/jdk1.6.0_20/ # echo $JRE_HOME... (6 Replies)
Discussion started by: pinga123
6 Replies

6. Shell Programming and Scripting

Simple Script needed for Processing CSV file perl

I am new to perl, and need a script to pull a CSV file, strip out 2 leading columns, and 2 ending columns, and resave the file in a new location. The file is basic and has less than 10,000 records. Secondly, can I schedule perl scripts to run daily? Can someone provide the basic script to... (1 Reply)
Discussion started by: cobbjob
1 Replies

7. Shell Programming and Scripting

Help needed in a Batch File

Hi Guys, I have a batch file that does a process "Import's sifs" & writes the log to a particular file. Sometimes in the log, it displays records with errors although there is no error. Explaination - IF SIF's are imported -> Successful IF SIF's are not imported -> Error IF SIF's are not... (2 Replies)
Discussion started by: nhanda
2 Replies

8. Programming

newbie to unix programming in C, needed a few simple prgs on these functions!

Hi all, I am a newbie to unix programming using C.. So i would like to have a few simple C programs to start off with.. I wanted programs on learning , abort,kill and raise,alarm and pause,I would also like to know how to use the vfork() in a prg It would be really great if i can have... (1 Reply)
Discussion started by: wrapster
1 Replies

9. UNIX for Dummies Questions & Answers

How to create an run a simple batch file?

Hi, So, I created a file named TEST.BAT in my home directory. In it, I wrote: #! /bin/bash echo Hello and then, saved the file. Then, at the command-line interface, I typed TEST.BAT, but the command-line never executes the file and thus, never returns "Hello". It says "command... (2 Replies)
Discussion started by: Hyunkel
2 Replies

10. Shell Programming and Scripting

simple script help needed

I am relatively new to *nix and have set up a small home network with a red hat server, what i would like to do is write a small script to check to see if a computer is connected by using the ip address of the computer. can get the ping to return but cant get the echo line working. the output i... (3 Replies)
Discussion started by: nobius
3 Replies
Login or Register to Ask a Question