I am working with the PBS queue on a server.
I want to submit several jobs automatically and
therefore need to replace a variable with a path.
Since it is not possible to get arguments into a
running script running with the queue, I want to
replace the shell variables that are normally used
with hardcoded parameters.
What I need is:
#! /bin/sh
#PBS -N runme_$file
#PBS -o $file.out
#PBS -e $file..err
#PBS -q batch
#PBS -j oe
#PBS -m abe
#PBS -r n
#PBS -l nodes=1:ppn=1
#PBS -l walltime=24:00:00
/home/example/proggie script $file $parameter2
echo "DONE"
replacing $file with ‘/tmp/output’, so it should be converted to:
#! /bin/sh
#PBS -N runme_/tmp/output
#PBS -o /tmp/output.out
#PBS -e /tmp/output.err
#PBS -q batch
#PBS -j oe
#PBS -m abe
#PBS -r n
#PBS -l nodes=1:ppn=1
#PBS -l walltime=24:00:00
/home/example/proggie script /tmp/output $parameter2
/home/example2/proggie2 /tmp/output
echo "DONE"
The PBS part is important because it hinders usage of parameters.
So i cannot just use $1 and $2 and give the script the parameters
it needs via arguments. Instead i have to change the file via a
substitution command, then i can submit it to the queuing system.
I still want to be able to use the script from the command line,
for quick testing.
I tried already using sed, but the possibility of special characters
occurring in the file screws up everything. There has to be a better way.
Using
sed:Using
awk(gawkor GNU Awk):In both examples, I assume that this editing context has the correct value for the file name in
$file. I’m also assuming that you don’t have any other variables such as$file1or$filenamein the script; if you do have such variables, the regular expressions have to be more complex. I also assume in thesedexample that you don’t embed percent symbols in your file names.