Replicating jobs, renaming outout

Can anyone tell me if it's possible to write a script that will repeat the same job several times but give the output a slightly different name each time (i.e. change or add a number at the end of the output file)? Here is the script I use to run a single job:

#!/bin/bash
#PBS -N job0
#PBS -l select=1:ncpus=1:mem=15gb
#PBS -k oe
#PBS -q workq
#PBS -l walltime=72:00:00
#PBS -M user@gmail.com
#PBS -m ea

source /etc/profile.d/modules.sh
module purge
module add gcc/4.5.1

cd $PBS_O_WORKDIR

/scratch/user/program -iprogram_0.u -oprogram_0.out

I know I can write separate bash files for each job but I want to know if I can write a script that will replicate jobs AND give the output a new name, without having to specify that all in a another bash file. Thanks.

You have already used a variable in the statement

cd $PBS_O_WORKDIR

You can do the same with the output files name. There are some special variables which content is maintained by the system and which you could use to modify the name of your output file.

For instance, there is "$$", which is the process number of the running process (your script). For instance:

outfile="program_0.$$.out"

...

/scratch/user/program -iprogram_0.u -o$outfile

This will be unambiguous, but not very helpful if you want to sort the files by i.e. date. You can also use the output of the date command to achieve this. See man date for various formats of output, one plausible version would be:

outfile="program_0.$(date +"%Y%m%d.%H:%M:%S").out"

I hope this helps.

bakunin