开发者

Looking for a bash script to run a program with different inputs on linux server

开发者 https://www.devze.com 2023-02-02 11:16 出处:网络
I knew how to write that bash once, but I can\'t figure it out anymore. As the title says, it should be script aimed at running on a Linux server.

I knew how to write that bash once, but I can't figure it out anymore.

As the title says, it should be script aimed at running on a Linux server.

My goal is to do those commands without having it typed again and again. (I'm chaining the input files in each run.)

bsprun -npes 1 ./a.out file1.txt file2.txt
bsprun -npes 2 ./a.out file1.txt file2.txt
bsprun -npes 3 ./a.out file1.txt file2.txt
bsprun -npes 4 ./a.out file1.txt file2.txt
bsprun -npes 5 ./a.out file1.txt file2.txt
bsprun -npes 6 ./a.out file1.txt file2.txt
bsprun -npes 7 ./a.out file1.txt file2.txt
bsprun -npes 8 ./a.out file1.t开发者_如何转开发xt file2.txt


Actually, after reading your description a bit more closely, perhaps you want this:

#!/bin/bash

bsprun -npes "$1" ./a.out "$2" "$3"

chmod +x the script then call it like

./myscript 1 file1.txt file2.txt
./myscript 2 file2.txt file3.txt
./myscript 3 file4.txt file5.txt
...

If your input files change according to a pattern we could make the script a bit smarter but it is unclear what your file names look like.

To get the exact output you posted, put it in a loop like:

#!/bin/bash

for i in {1..8}; do
  bsprun -npes $i ./a.out file1.txt file2.txt
done


If you want to do it continually, use this:

  #!/bin/bash

i="1"

while true;
do
    if [ $i -eq 9]; then
       i=1
    fi
    bsprun -npes $i ./a.out file1.txt file2.txt
    i = `expr $i + 1`
done


It sounds like you want to learn to write BASH, you may want to take a look at

https://github.com/37signals/sub

its helped me a lot with keeping my scripts organized

also google is your friend

bash script loop example

the above search returns a ton of results exactly what you are looking for

0

精彩评论

暂无评论...
验证码 换一张
取 消