简体   繁体   中英

Combining couple of commands inside the bash / python script

I am already doing my job with couple of commands, but I need manual effort and have to observe the job each time. So I want everyhing to be done automatically and I should only be notified if desired result happens. So my scenario is below;

I create results with my script stv.sh

Cmd 1: >> timeout 15m./stv.sh -parameter1 -parameter2 -output file file1.txt

than I take the necessary fields from my raw tex file to anoher file

Cmd 2: >> sed file1.txt -parameter1 -parameter2 -output file cleanfile1.txt

than I am adding a test line to my text file

Cmd 3: >> cat testline.txt >> cleanfile1.txt

than I compare my new file with my existing results to find any matching lines

Cmd 4: >> comm -12 myexistingresults.txt <(cat cleanfile1.txt | sort | uniq ) > matching.txt

now, in the matching.txt, at least 1 result will appear in any case because we've included testline.txt with Cmd 2. But if there is more than one line, the command below needs to run;

Cmd 5: >> grep -A 2 $secondlineofmatchingtxt file1.txt > victory.txt

that means I found a matching line. So, in the matching.txt, if there is more than one line I need to be notified somehow (by sending e-mail etc.), else if there is only one line in matching.txt, the script needs to start from Cmd 1 again.

How can I establish this goal with a simple bash or python script?

Create a file to add the interpreter at the top of the file, #!/bin/bash and then enter all the commands into one file, allow executable permissions on the file and then run the file.

For the email part you might want to use the exit code of the script ./stv.sh file. After running this script successfully, find the exit code, and create an if statement to test if the exit code matches and if does match, then the email will be sent. Otherwise another way would be to check if the file1.txt exists, but this might not be accurate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM