LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux 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


Reply
  Search this Thread
Old 10-20-2017, 01:40 PM   #1
atjurhs
Member
 
Registered: Aug 2012
Posts: 220

Rep: Reputation: Disabled
how do i batch execute multiple line commands


hi guys,

i need to run the same python executable command on multiple input files, each having a different input path, and then write the output files to a different output path.

then i change a setting within the python code and re-run it on the same set of input files.

the python executable is coded to know what input file it needs in the input directory and it automatically dumps out a set of files in the output directory.

for example, with the executable having the first setting value, i run each line command by hand:
Code:
py27 exe.py -r /input_path1 -o /output_path1
py27 exe.py -r /input_path2 -o /output_path2
py27 exe.py -r /input_path3 -o /output_path3
py27 exe.py -r /input_path4 -o /output_path4
py27 exe.py -r /input_path5 -o /output_path5
etc...
then i look at the output files, and then change the executable's setting to a different value and re-run each line command by hand:

Code:
py27 exe.py -r /input_path1 -o /output_path1
py27 exe.py -r /input_path2 -o /output_path2
py27 exe.py -r /input_path3 -o /output_path3
py27 exe.py -r /input_path4 -o /output_path4
py27 exe.py -r /input_path5 -o /output_path5
etc...
this process is very tedious.

what i'd like to do is to copy all the line commands into a single text file and then run an bash or AWK command (or something similar) on that text file to "batch" process the line commands, then i can change the setting's value in the python code, and re-run the batch.

i suspect this batch processing can be done inside the python code, only i'm not the owner of the code and it's waaaay outside my ability to write python, but i do understand a bit of bash and AWK

so i'm thinking something very crude like...

Code:
#!/bin/sh
ListOfLineCommands.txt | { while read each line ; do
     py27 exe.py )
     done
}
can anybody help me? i'd really appreciate it!

thanks!

Todd

Last edited by atjurhs; 10-20-2017 at 01:58 PM.
 
Old 10-20-2017, 02:01 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,496

Rep: Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108
One quick script.

Code:
#!/bin/bash

while read in out
do
  py27 exe.py -r $in -o $out
done < "data-file"
and data-file contains
Code:
/input_path1 /output_path1
/input_path2 /output_path2
/input_path3 /output_path3
/input_path4 /output_path4
/input_path5 /output_path5
 
2 members found this post helpful.
Old 10-20-2017, 02:11 PM   #3
atjurhs
Member
 
Registered: Aug 2012
Posts: 220

Original Poster
Rep: Reputation: Disabled
hi michaelk, and thanks!

i was just thinking about maybe a for loop before you replied

something like

Code:
#!/bin/bash
for i in ListOfLineCommands.txt; do
    echo py27 exe.py
    $i
done
BUT...

what is meant by your "while read in out"? don't while loops generally look like

Code:
while read line
or
Code:
while [some sort of a $count]
can you tell i'm a total hack at this

Last edited by atjurhs; 10-20-2017 at 02:20 PM.
 
Old 10-20-2017, 02:22 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,496

Rep: Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108Reputation: 4108
Not necessarily.

The while loop is reading the contents of a text file. done < "data-file"

The read command (read in out) is requesting two strings which is assigned to the variables in and out.
 
1 members found this post helpful.
Old 10-20-2017, 02:23 PM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
If you're lazy just extract the lines from .bash_history into a .sh file.

$ history | grep -i exe.py | tee myscript.sh
$ chmod +x myscript.sh
$ nano myscript.sh

Add a header
Code:
#!/bin/bash
Add a footer
Code:
exit 0
And delete any lines you didn't want to do / duplicates / false positives and whatnot.
 
Old 10-20-2017, 02:47 PM   #6
atjurhs
Member
 
Registered: Aug 2012
Posts: 220

Original Poster
Rep: Reputation: Disabled
michaelk, it worked, cool! and thank you!

i'll remember how to do this for later on

Todd
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to execute multiple commands on remote server AshwiniIngale Programming 14 01-26-2013 12:54 PM
[SOLVED] Bash script to read line by line and execute commands Striketh Programming 4 11-06-2011 11:38 AM
How to execute multiple commands with find and -exec... tomstratton Linux - General 6 05-26-2009 03:26 AM
To execute two commands in a single line remotely ZAMO Linux - General 12 10-31-2008 01:31 AM
can ssh execute multiple commands at the same time? Singist Linux - Networking 2 04-04-2006 09:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
Open Source Consulting | Domain Registration